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

0 votes

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
3,724 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.

0 votes

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
• 6,890 points
0 votes
Check if you've added hostnames in the inventory file.
answered Apr 23 by Keshav
0 votes
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 by Lavanya

Related Questions In Ansible

0 votes
1 answer

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 13, 2018 in Ansible by DareDev
• 6,810 points
209 views
0 votes
1 answer
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
207 views
0 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
• 6,890 points
1,654 views