Automating your Datacenter Network (NXOS) with Ansible

As a Datacenter Networking Expert, I felt that I need to always perform a network health check every morning as I take my morning coffee to ensure that my infrastructure is working properly.

I was doing my datacenter network health check manually, then I tried to employee my ansible skills to automate my network health check.

Here are the requirements:

  • Linux OS preferer Centos ( it can be VM or bare-metal or PC ).
  • That is it !

Step-1: Install Ansible (Linux Centos 7)

sudo yum update
sudo yum install ansible

Step-2: Setup your inventory (Switches)

nano /etc/ansible/hosts

in bellow example my host group “DC-SW” and “dc-sw1/2” are my switches hostname.

Note: to exit nano editor and save press ctlr + ‘x’ then ‘y’.

Step-3: Create your playbook

nano playbook.yml
---

- name: CORE SWITCHES
  hosts: DC-SW
  gather_facts: false
  connection: network_cli

  tasks:
    - name: health check
      ios_command: 
        commands: 
          - show  int stat down
          - show int des | include "Interface description"
          - show cdp nei
          - show lldp nei
          - show ver | i system
          - show ver | i kick
      register: results
    
    - name: print results
      debug:
        var: down.stdout_lines

Step-4: Run your Playbook

ansible-playbook -i inventory playbook.yml <-(your playbook name.yml) --ask-pass --user (your user)