Connecting to new EC2 instance using .pem file

1,417 views
Skip to first unread message

Lokesh Vastrad

unread,
Jun 18, 2015, 10:04:51 AM6/18/15
to ansible...@googlegroups.com
Hi,

I am new to Ansible. I have setup Ansible using source from GIT. I am able to provision a new EC2 instance. I want to connect to this instance using a .pem file and not ssh.

I am able to manually connect to the new instance using the .pem file with the command "ssh -i abc.pem ec2-user@instance". However, I am unable to connect using ansible parameter.

Command:

ansible-playbook abc.yml --private-key=/path/to/file.pem

Error: ip | FAILED! => SSH encountered an unknown error during the execution. 

I also created an ansible.cfg file in the current directory and added the private key file path parameter. Nothing is working for me. Basically, none of the paramters are set from the ansible.cfg file.

Please let me know what I am doing wrong here.

Thanks,
Lokesh

Andrew Burrow

unread,
Jun 18, 2015, 11:30:39 PM6/18/15
to ansible...@googlegroups.com
Possibly start by running the trivial ping module in verbose mode:

ansible all -m ping -vvvv

Lokesh Vastrad

unread,
Jun 23, 2015, 12:53:07 AM6/23/15
to ansible...@googlegroups.com
Hi Andrew,

Thanks a lot for your reply. I was able to overcome the issue by creating a config file and adding few details under .ssh folder. I am now able to connect to the server.

Thanks,
Lokesh

Alexey Shabalin

unread,
Jun 23, 2015, 11:44:28 AM6/23/15
to ansible...@googlegroups.com
Hi Lokesh,
Could you please tell me in more details, what exactly you did to solve your issue?

hamzeh alsalhi

unread,
Jun 24, 2015, 3:37:52 PM6/24/15
to ansible...@googlegroups.com
I don't know what op did. I've solved this issue by doing:
$exec ssh-agent bash
followed by:
$ssh-add my_ec2_key.pem

Then I am able to run a playbook on the ec2 instance simply by listing the ip in the hosts file.
Reply all
Reply to author
Forward
0 new messages