Connecting from Ansible to remote Linux machines

Posted: January 26, 2018 in Amazon Web Services (AWS), ansible, Linux

Creating key pair on Ansible server


Private/public key will be created


Copy content of pub file to clipboard, make ssh connection to remote machine which will be managed by Ansible

ssh root@

copy public key to ~/.ssh/authorized_keys from clipboard

[root@web .ssh]# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLIXNj9M0GsRJMml6VqH0eN0krM0O6A83D5V2PK0V/Qib6YPUcq9W5kq89BDIub86owmTQZ8pQwKqvQNPkZ/+MmIxdBE2Dfa7/dSsSpmP7EKs5HLHsd9KRapbzk3tSgAtX9dkcs2MioZbTjxA2P1r2N3nIxTjyYzkorUvBQX+unPLqSS5l9t+ByP7LJYOFZdlrkvtbICnsp4dOzW7+f0E+HKMYLpT/KerN245ot//COoVTjxshbcRcry4Olv3qO2yvKZBlRx5zZAWJcUXlNCm5axNTGUBP+ohcHEois5nBSXf9VrIEPF+hpk4XeBEAMAnIe+MTTxlKqBafGTv2SvNN root@ansible

Connecting to Amazon EC2 instance

We need first to copy key pair from Amazon to Ansible server (with pem extension)


Add following lines to /etc/ansible/hosts (create it if don’t exists)

aws_instance ansible_host='public ip' ansible_user='ec2-user' ansible_ssh_private_key_file='/myproject/test.pem'


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s