FreeKB - Ansible ansible ad hoc ping command
Ansible - ansible ad hoc ping command

The ansible ad-hoc command can use the ping module to ping managed nodes (the target systems). Let's say you have the following managed nodes defined in the default hosts file or your own inventory file.

windows:
  hosts:
    server1.example.com:
    server2.example.com:
linux:
  hosts:
    server3.example.com:
    server4.example.com:

 

Here is how you would use the ansible command to ping all of the managed nodes. 

ansible all -i inventory.yml --module-name pingĀ 

 

If all of the hosts are reachable, something like this should be returned.

server1.example.org | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
server2.example.org | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
server3.example.org | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
server4.example.org | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

 

Let's say the following is returned. 

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 managed 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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 6d767 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |