1
votes

I am very new to ansible. I have managed to install it and set up the ec2.py file via the git and set up the IAM root user. but my question is I already have a ec2 instance online that uses a .pem file that amazon has created. i use windows and have created the relative .ppk file when i try to ssh into that ec2 instance from another ec2 instance I see that via cd ~/.ssh/ the files authorized_keys and known_hosts are created but when i run ssh [email protected].... I get a permission denied (puplickey) I examined the contents of the authorized_keys file and the ppk and pem file and it seems that the public key is stored in the authorized_keys file correctly and the user is correct. Am I correct in thinking that I need to copy the private key into this file?(although I don't really want to) or is it because I need a passphrase? and in relation to ansible How do I utilise this key to manage the host in the same VPC?

Edit (extra): I found out that the authorized_keys file is the file that contains the public key and fingerprint. when i edited the file i was no longer able to access the EC2 instance and it kept asking for a password and saying that the fingerprint had changed. so I guess that's why its best practice to create a ssh-key on the ansible system and then import into AWS

1
"Am I correct in thinking that I need to copy the private key into this file?" -- no you are not correct.techraf
Thanks for confirminguser3700919

1 Answers

2
votes

If you can ssh to the host in question via putty with key.ppk file, then:

  • convert key.ppk back into key.pem
  • place key.pem somewhere onto the control host (where Ansible is installed)
  • define inventory (hosts file) for Ansible:

    myserver ansible_host=ip-or-dns-of-your-server ansible_user=your-user ansible_ssh_private_key_file=path/to/key.pem

  • run ansible myserver -m ping to confirm connectivity

This way Ansible will try to connect to your server aliased myserver at ip-or-dns-of-your-server with your-user account using path/to/key.pem private key.