Unable to ping my remote machine using Ansible

2.1k Views Asked by At

I have a remote machine to which I want the connection to be set.

This is my hosts file:

[remote]
192.168.51.2

where 192.168.51.2 is the private ip of the remote machine.

When I try pinging it using ansible remote -m ping, I get the following error:

192.168.51.2 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}

I did not mention the credentials of that remote machine anywhere, but I don't think that's the problem here. It is failing to connect via SSH.

What do I do?

2

There are 2 best solutions below

3
techraf On

I did not mention the credentials of that remote machine anywhere, but I don't think that's the problem here. It is failing to connect via SSH.

This is the exact cause of your problem.

Ansible does not use a network (ICMP) ping, but a more complex procedure involving logging on to a remote machine via SSH and running Python script to respond.

You must provide the credentials either in the form of the private-public key-pair or a password.

Ansible basics are well documented and available here. The Remote Connection Information section of the Getting Started guide explains the way Ansible connects to remote hosts.

0
Super Kai - Kazuya Ito On

Leave the fingerprint of the master server to the remote server first before pinging to the remote server with ansible.

So "log in & log out the remote server first from the master server. Then, ping to the remote server with ansible."

I also couldn't ping to a remote server so I did the solution above ↑↑↑ Then, I could ping to the remote server.

I don't know what's happening backside but this solution will work.