6

I just started learning the basics of Ansible, and looked up why I am getting the above error but can't figure out how to sort it out. This is the trace:

Me-Air:ansible me$ ansible all -m ping -vvv
Using /private/etc/ansible/ansible.cfg as config file
<Public_IP> ESTABLISH SSH CONNECTION FOR USER: [my_user_name_on_EC2_instance]
<Public_IP> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/Users/me/.ansible/cp/ansible-ssh-%h-%p-%r -tt [Public_IP] '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-... `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-... `" )'"'"''
Public_IP | UNREACHABLE! => {
    "changed": false,
    "msg": "SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue",
    "unreachable": true
}

------

I was previously asked:

The authenticity of host 'public IP' can't be established.
RSA key fingerprint is ...[key].
Are you sure you want to continue connecting (yes/no)? yes

This is what I have in the hosts file:

[name_of_the_EC2_instance]
Public_IP 

And in the config file:

[defaults]
host_key_checking = False

I'm missing something there. Any ideas?

Thanks in advance.

  • 1
    what happens when you run it with -vvvv? can you ssh to the public IP? The fact it prompted you to prompt the hostkey indicates the config is being ignored. What is the local config called and where is it relative to where you are running Ansible? – tedder42 Mar 26 '16 at 18:36
  • Yes I can ssh to this IP, but so when I run it with -vvvv I get : SSH encountered an unknown error. with a very long trace ending with Trying private key: /Users/me/.ssh/id_dsa\r\ndebug3: no such identity: /Users/me/.ssh/id_dsa: No such file or directory\r\ndebug2: we did not send a packet, disable method\r\ndebug1: No more authentication methods to try.\r\nPermission denied (publickey).\r\n" – David B. Mar 26 '16 at 18:52
  • where are you specifying the private key? (suggestion: in the ansible.cfg). It appears it can't find your ssh key. – tedder42 Mar 26 '16 at 19:05
  • Ah you mean the private key to connect to the EC2 instance? Nowhere indeed. So I addded it to the command line: ansible all -m ping -u my_user --private-key=~/path_to_key/my_private_key.pem. And it worked. Possible to add the key directly in the ansible.cfg file? – David B. Mar 27 '16 at 10:04
8

As explored in the comments, the private key file was not being specified. The default files (.ssh/id_dsa, .ssh/id_dsa) were attempted but not found.

The private key file can be added in several ways:

(1) Using the ssh agent: ssh-add ~/.ssh/my-key.pem

(2) Defaulted in ansible.cfg:

[defaults]
private_key_file=~/.ssh/my-key.pem

(3) Specified per host in inventory:

my-host-ip ansible_ssh_private_key_file=~/.ssh/my-key.pem
  • 1
    yeah, I had to issue the ssh-add ~/.ssh/id_rsa command (mentioned in the tutorial as well) and then it worked. I didn't think of this right away, cause I usually don't have to do it, but I upgraded OS X recently, so I guess this agent got cleared in the process. – metakermit Oct 11 '16 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.