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?
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.