2

I'm trying to get set up with Ansible for the first time, to connect to a Raspberry Pi. Following the official 'getting started' steps, I've made an inventory file:

192.168.1.206

.. but the ping fails as follows:

$ ansible all -m ping -vvv
No config file found; using defaults
<192.168.1.206> ESTABLISH SSH CONNECTION FOR USER: pi
<192.168.1.206> 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 User=pi -o ConnectTimeout=10 -o ControlPath=/Users/username/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.1.206 '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1464128959.67-131325759126042 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1464128959.67-131325759126042 `" )'"'"''
192.168.1.206 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh.",
    "unreachable": true
}

This looks the same as this question, but adding password/user bits make no effect for me, shouldn't be necessary to ping, and aren't in the official example anyhow. In any case I'd prefer to configure Ansible to use a specific public/private key pair (as per ssh -i ~/.ssh/keyfile method..)

Grateful for assistance.


Oh and yes the Raspberry is available at that address:

$ ping 192.168.1.206
PING 192.168.1.206 (192.168.1.206): 56 data bytes
64 bytes from 192.168.1.206: icmp_seq=0 ttl=64 time=83.822 ms
Community
  • 1
  • 1
geotheory
  • 22,624
  • 29
  • 119
  • 196
  • Have you tested that you can ssh to it without a password or with the password that you provide in the appropriate variable? – Matthew Schuchard May 24 '16 at 23:45
  • Yeah ssh works fine, either with password or the `-i ~/.ssh/keyfile` method. – geotheory May 25 '16 at 00:01
  • Then you know ssh works and `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 User=pi -o ConnectTimeout=10 -o ControlPath=/Users/username/.ansible/cp/ansible-ssh-%h-%p-%r` does not. Time for a binary search, although I do notice the control path user does not match the user in the ssh command. – Matthew Schuchard May 25 '16 at 00:35
  • You mean that `pi` doesn't match `username`? If so, when I specify `username` in `/etc/ansible/hosts` I get `<192.168.1.206> ESTABLISH SSH CONNECTION FOR USER: username` but followed by an otherwise identical error message. – geotheory May 25 '16 at 07:55
  • Was it unclear by what I meant by 'binary search'? You need to take Ansible's ssh command, verify it does not work as it is, and then start trying it with one argument removed at a time to see what is the perpetrator here. I know this is literally not a binary search, but I was attempting some slight humor. – Matthew Schuchard May 25 '16 at 11:15
  • Sounds sensible, but how do I approach this practically speaking? Isn't a ping the most basic test? – geotheory May 25 '16 at 12:38
  • Look at this from a control/experimental variable perspective. You know `ssh` works. You know `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 User=pi -o ConnectTimeout=10 -o ControlPath=/Users/username/.ansible/cp/ansible-ssh-%h-%p-%r` does not. Therefore, you know you need to isolate the difference between those two commands that is causing your failure. – Matthew Schuchard May 25 '16 at 12:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112952/discussion-between-geotheory-and-matt-schuchard). – geotheory May 25 '16 at 18:11
  • Finally, what was the issue ? I'm facing the same – Kevin Vincent Dec 11 '16 at 17:12
  • Sorry I gave up on the end. Overwhelmed by the SO response.. – geotheory Dec 11 '16 at 18:24

3 Answers3

0

Despite what its name could suggest, Ansible ping module doesn't make an ICMP ping.

It tries to connect to host and makes sure a compatible version of Python is installed (as stated in the documentation).

ping - Try to connect to host, verify a usable python and return pong on success.

If you want to use a specific private key, you can specify ansible_ssh_private_key_file in your inventory file:

[all]
192.168.1.206 ansible_ssh_private_key_file=/home/example/.ssh/keyfile
Eric Citaire
  • 4,355
  • 1
  • 29
  • 49
0

It works for me.

10.23.4.5 ansible_ssh_pass='password' ansible_user='root'

Kairat Koibagarov
  • 1,385
  • 15
  • 9
0

You can also troubleshoot by executing ssh in debug mode and compare the results when running:

ssh -v pi@192.168.1.206

with:

ansible all -m ping -vvvv
mottek
  • 929
  • 5
  • 12