0

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?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
prudhvi
  • 1,141
  • 6
  • 23
  • 46
  • The naming of the Ansible ping module is misleading. What the module actually does is connect to the host and execute a script on the host which returns pong. – Henrik Pingel Oct 31 '16 at 12:52
  • @HenrikPingel How does your comment differentiate from my answer? Just wondering why did you feel a need to state this... – techraf Oct 31 '16 at 13:14

2 Answers2

1

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.

techraf
  • 64,883
  • 27
  • 193
  • 198
  • I exchanged the pub files of these machines using ssh-keygen. Is this what I have to do? Or 2.) I have username and password for the remote machine. Should I put them in a file on my controller node? I am not understanding how to put them. Till now, I worked with AWS machines and they used to have .pem files which I used to put here. But for this, I need to give username and password. What are the parameters for them? Ex. username : dvvfve , password : jfviwneojrin! – prudhvi Oct 31 '16 at 13:01
  • First, you need to start expressing your thoughts and questions clearly, because what you write is incomprehensible as a whole. – techraf Oct 31 '16 at 13:16
  • Module name tends to confuse it with the most commong "ping" understanding, but indeed is explained in the docs so it's a user mistake. Btw, there's no easy way to ping all servers inside a group that is not ssh intended. – m3nda Jul 04 '17 at 00:36
0

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.

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129