

In my case, some of my hosts are running with modified SSH port for security reasons so I should be able to instruct Ansible to use the right port.

The ansible_port is to define the SSH port number to be used while connecting to the remote server. Because in real-time, we might have different distributions of Linux servers running in our infra like ubuntu, centos, ec2-user etc. The reason we are defining the ansible_user is to be able to use different types of EC2 instances with different user IDs. We have a host file with a hostgroup named hosts_to_add_key and we have defined our host-specific properties including what username should be used for each host Preparing the hosts file with multiple hosts and distributions Do not use the main branch as it is intended for the other method to add SSH key to default user git clone -branch UserCreate-SSHAdd The Playbook can be copied from this post or cloned from the Git hub repository branch. Playbook to add users in EC2 instance and copy SSH key.


