How to login into the AWS EC2 instance using SSH for performing ansible playbooks & ansible roles.

Kalyan Kalapala
2 min readAug 10, 2020

1) Create ssh keypair & copy ssh of the remote server with the public key.

2) Insert the copied remote server IP address in the /etc/ansible/hosts file & checking the status of the HTTPD service.

3) Now if the AWS EC2 instance gets rebooted or stopped we can attain the status of the remote server even the public IP address gets changed.

a) Now we had stopped the EC2 instance.

b) Again we started the same EC2 instance & it is observed that the IP address got changed.

c) Now let’s try to ssh into this EC2 instance using the public key.

As you can see, it didn’t prompt for the password to login into the remote server using SSH.

d) We’ll change the IP address of this remote server in the /etc/ansible/hosts file and check the HTTP status again.

Finally, we are able to run the ansible and check the status of the HTTP service of the remote host even the AWS EC2 instance public IP address gets changed each time on the stopping or rebooting of the EC2 instance.

--

--