Use Ansible to Test Clos Ping Connectivity

  • 1 July 2016
  • 0 replies

Userlevel 2
I wanted to share something I have been using for a while to test ping connectivity using Ansible. I use this super short and super simple playbook to do an eye check on my switch connectivity after making a change. Ideally you would integrate something like Behave or ServerSpec into your Continuous Integration and Development process, so that any changes are automatically tested and given a pass or fail. That is not always something you can create on the fly when starting a new deployment or project or just simply testing out a new feature.

How is this working?
Ansible has a variable called 'hostvars' that allows for accessing information about other hosts. Here I use hostvars[item] to pull out variables for each host during the play and specifically grab the ipv4 addresses local to that host. Those addresses are appended to a list and the ping command is run on each host for all ipv4 address collected for each and every host.

- hosts: network
remote_user: root

- name: set an empty list named ips
ips: [] - name: append all known IPv4 addresses from the group network set_fact: ips: "{{ ips + hostvars[item].ansible_all_ipv4_addresses }}" with_inventory_hostnames: network - name: ping all IP addresses in ips shell: "ping {{ item }} -c 1" with_items: - "{{ ips }}" register: result changed_when: "result.rc != 0"

0 replies

Be the first to reply!