prudhvi prudhvi - 11 days ago 5
Linux Question

Unable to ping my remote machine through Ansible

I am trying to ping my remote linux machine using the following command :

ansible remote -m ping -vvvv


I get the following response :

[root@ansible ansible]# ansible remote -m ping -vvvv
Using /etc/ansible/ansible.cfg as config file
Loaded callback minimal of type stdout, v2.0
<192.41.50.9> ESTABLISH SSH CONNECTION FOR USER: root
<192.41.50.9> SSH: EXEC sshpass -d12 ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.41.50.9 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1480431200.39-212981181831507 `" && echo ansible-tmp-1480431200.39-212981181831507="` echo $HOME/.ansible/tmp/ansible-tmp-1480431200.39-212981181831507 `" ) && sleep 0'"'"''
192.41.50.9 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}


My hosts file looks like this :

[remote]
192.41.50.9

[remote:vars]
ansible_ssh_user=root
ansible_ssh_pass=p@ssw0rd
ansible_ssh_port=22


When I tried to ssh into my remote machine, this is what i got :

[root@ansible ansible]# ssh root@192.41.50.9
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
86:d2:ca:8e:aa:8a:ce:25:c7:e5:31:7e:2a:c0:11:7f.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending RSA key in /root/.ssh/known_hosts:3
RSA host key for 192.41.50.9 has changed and you have requested strict checking.
Host key verification failed.


What might be the reason for this connection failure?

Answer

If you read the output of the shell ssh, you'll find that

  1. you are being attached by a man-in-the-middle attack (very unlikely)
  2. the ssh key on the server has changed (because you re-created it and kept the same IP).

If your case is the latter one, you can add the following section in your ansible configuration file ansible.cfg

[defaults]
host_key_checking=False