# ping multiple gateways

**URL:** <https://forum.ansible.com/t/ping-multiple-gateways/20501>\
**Category:** Ansible Project\
**Created:** [February 9, 2016, 7:04pm UTC](https://forum.ansible.com/t/ping-multiple-gateways/20501 "2016-02-09T19:04:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Portia\_Wong](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@Portia\_Wong](https://forum.ansible.com/u/Portia_Wong)\
**Post date:** [February 9, 2016, 7:04pm UTC](https://forum.ansible.com/t/ping-multiple-gateways/20501/1 "2016-02-09T19:04:51Z")

</div>

Currently at my workplace, our hosts have multiple connections to different gateways. I am trying to find a way to see whether I can easily ping 4-5 gateways by either running an ad-hoc command or through a playbook to help me verify that after each host deployment, connection to those gateways are successful. Has anybody ever done this before?

---

<div class="post-metadata">

**Author:** ![wintelgeeks](https://avatars.discourse-cdn.com/v4/letter/w/3bc359/32.png) [@wintelgeeks](https://forum.ansible.com/u/wintelgeeks)\
**Post date:** [February 11, 2016, 3:13pm UTC](https://forum.ansible.com/t/ping-multiple-gateways/20501/2 "2016-02-11T15:13:05Z")

</div>

If I’m understanding it correctly, you are looking for a way to validate if your gateways are pingable. I usually do it using a Excel Ping script where i mention the gateway IPs and hit execute to test if they are reachable. Link to the script. **[http://wintelgeeks.com/2016/02/11/script-to-ping-multiple-servers-using-excel/](http://wintelgeeks.com/2016/02/11/script-to-ping-multiple-servers-using-excel/)**

---

<div class="post-metadata">

**Author:** ![Benjamin\_Redling](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@Benjamin\_Redling](https://forum.ansible.com/u/Benjamin_Redling)\
**Post date:** [February 11, 2016, 4:57pm UTC](https://forum.ansible.com/t/ping-multiple-gateways/20501/3 "2016-02-11T16:57:24Z")

</div>

The following req. /bin/ping -- don't forget to limit the ping count.

$ cat ping-list.yml  
# Simple ad hoc gateway ping. Prefer proper monitoring.

---

<div class="post-metadata">

**Author:** ![Chris\_DiGiovanni](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@Chris\_DiGiovanni](https://forum.ansible.com/u/Chris_DiGiovanni)\
**Post date:** [February 18, 2016, 10:22pm UTC](https://forum.ansible.com/t/ping-multiple-gateways/20501/4 "2016-02-18T22:22:28Z")

</div>

This is do-able as I just wrote a module for my current employer that does just this. The module needs to be cleaned up but I’ll see if they are willing to opensource it. ← could be a while… The module works by grabbing each interface’s IP and CIDR Mask. I then process the routing table to get a list of gateways I should be able to hit per interface. I then run the ping command to all the gateways recording the success or failure. For interfaces that don’t have any routes, I created a second test where it generates the first two host IPs in the network and it pings them. If one of those return successful the module considers it as a pass. All pings and data are collected and processed before a call to module.fail is called so I can include all of the test results in the output. This took about 2 days to write and another half day testing across several distros to give you an idea if you wanted to attempt yourself.

-Chris
