Ansible - Resolve "unreachable could not resolve hostname name or service not known"
by
Jeremy Canfield |
Updated: September 18 2021
| Ansible articles
Let's say the following is returned when invoking the ad-hoc ansible command or ansible-playbook command.
server1.example.com | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname server1.example.com: Name or service not known",
"unreachable": true
}
This suggests that the managed nodes hostname (server1.example.com) cannot be resolved to an IP address, which you can confirm using the nslookup command.
~]# nslookup server1.example.com
Server: 192.168.0.6
Address: 192.168.0.6#53
** server can't find server1.example.com: NXDOMAIN
In this scenario, you would have to consult with the team in your organization that manages DNS (probably the networking team) to determine why DNS is unable to resolve the hostname to an IP address.
If you are just doing local testing, you can add an entry like this to the /etc/hosts file on your Ansible control node to resolve the hostname to an IP address.
10.17.4.56 server1.example.com
Did you find this article helpful?
If so, consider buying me a coffee over at