ping multiple gateways

117 views
Skip to first unread message

Portia Wong

unread,
Feb 9, 2016, 2:07:41 PM2/9/16
to Ansible Project
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?

winte...@gmail.com

unread,
Feb 11, 2016, 10:45:17 AM2/11/16
to Ansible Project
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/

Benjamin Redling

unread,
Feb 11, 2016, 11:57:34 AM2/11/16
to ansible...@googlegroups.com
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.
---
- hosts: all:my_special_remote_host:!not_the_broken_one

tasks:

- name: check gateways after deployment
command: /bin/ping -c3 {{ item }}
with_items:
- 192.168.1.1
- gateway1.example.org

There are more elaborate solutions
In my reading list, not tested (autopinger):
http://jedelman.com/home/network-test-automation-with-ansible/

/Benjamin
--
FSU Jena | JULIELab.de/Staff/Benjamin+Redling.html
vox: +49 3641 9 44323 | fax: +49 3641 9 44321

Chris DiGiovanni

unread,
Feb 18, 2016, 5:22:28 PM2/18/16
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages