Error message Failed to connect to the host via ssh while running ping command on host machines through Ansible

0 votes

I have been trying to connect to machines and run a ping command on nodes using ansible. I am getting the below message.

ansible -i inventory all -m ping

Error Message:

centosinstance | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname centosinstance: Name or service not known\r\n", 
    "unreachable": true

I have also stated the private key file and the remote user name in ansible.cfg file.

Can anyone help me with this issue ?

Apr 25, 2018 in Ansible by Atul
• 10,230 points

1 answer to this question.

0 votes

Just go through the error message:

Ansible can't be able to resolve the centosinstance hostname. You just need to modify your inventory as :

centosinstance ansible_ssh_host=
centosinstance1 ansible_ssh_host=
Then, change the ip addresses with the ip addresses of your machines and try it one more time. I hope this time it will work.

answered Apr 25, 2018 by shubham
• 7,320 points

Related Questions In Ansible

+1 vote
2 answers

Running ansible command on a single server when it is deployed to multiple servers

You can try the run_once attribute: Example from ...READ MORE

answered Jun 14, 2018 in Ansible by DareDev
• 6,890 points
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
+2 votes
1 answer
+1 vote
3 answers
0 votes
1 answer

How do I execute a shell script and then use the result in ansible

This can work out for you: - name: ...READ MORE

answered Apr 11, 2018 in Ansible by shubham
• 7,320 points