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

+1 vote

I tried to connect to machines and ran a ping command on nodes using ansible. I have been getting the the below message.

command: ansible -i inventory all -m ping

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 had stated the private key file and the remote user name in ansible.cfg file.

Apr 30, 2018 in Ansible by Atul
• 10,240 points
20,571 views
Are you doing this on a Linux distro?
Yess, both host and server on Ubuntu
Are you able to ssh into your host from the server?
No I'm not! Do I have to first create an ssh connection?
Yes obviously, create an ssh connection first

3 answers to this question.

+1 vote

Just read the below error message:

ssh: Could not resolve hostname centosinstance: Name or service not known

Ansible can't be able to resolve the centosinstance hostname.

Modify your inventory like this:

centosinstance ansible_ssh_host=192.168.1.10
centosinstance1 ansible_ssh_host=192.168.1.11

Change the ip addresses with the ip addresses of your machines and try one more time.

Hope that help it will resolve your problem.

answered May 1, 2018 by shubham
• 7,340 points
+1 vote
Check if you've added hostnames in the inventory file.
answered Apr 23, 2019 by Keshav
+1 vote
I hadn't created the ssh connection between my hosts and the servers. I created an ssh key on my server, copied that to my hosts and the error disappeared.
answered Apr 23, 2019 by Lavanya

Related Questions In Ansible

+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
4,058 views
+2 votes
1 answer
0 votes
1 answer
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,340 points
6,912 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP