Featured image

Table of Contents Link to heading

Simple Network Automations Link to heading

Reprieving Network Information Link to heading

A simple playbook to gather device facts and interface details:

- name: Collect device facts
  hosts: all
  gather_facts: no
  tasks:
    - name: Gather network facts
      cisco.ios.ios_facts:

Run the playbook:

ansible-playbook get_facts.yml -i inventory.ini

Deploying VLANs Across Switches Link to heading

Instead of manually configuring VLANs on every switch, use Ansible:

- name: Configure VLANs
  hosts: switches
  tasks:
    - name: Create VLAN
      arista.eos.eos_vlan:
        vlan_id: 100
        name: Management_VLAN
        state: present

Run the playbook:

ansible-playbook configure_vlan.yml -i inventory.ini

Backing Up Network Configurations Link to heading

Automate backups to ensure configurations are stored securely:

- name: Backup Router Configurations
  hosts: routers
  tasks:
    - name: Save running config
      cisco.ios.ios_command:
        commands:
          - show running-config
      register: output

    - name: Write to file
      copy:
        content: "{{ output.stdout_lines }}"
        dest: "/backup/router_config_{{ inventory_hostname }}.txt"

Run the playbook:

ansible-playbook backup_configs.yml -i inventory.ini

Advanced Network Automations Link to heading

Automating Router Firmware Upgrades Link to heading

Keeping network devices updated with the latest firmware can be a tedious process. Here’s an Ansible playbook to automate this task across multiple routers:

- name: Upgrade Router Firmware
  hosts: routers
  tasks:
    - name: Upload firmware file
      cisco.ios.ios_command:
        commands:
          - copy tftp://192.168.1.100/cisco_fw.bin flash:cisco_fw.bin

    - name: Verify firmware version
      cisco.ios.ios_command:
        commands:
          - show version
      register: firmware_output

    - name: Display firmware version
      debug:
        msg: "{{ firmware_output.stdout_lines }}"

Run the playbook:

ansible-playbook upgrade_firmware.yml -i inventory.ini

Monitoring Network Performance Link to heading

Instead of logging into each network device manually, automate network health monitoring using Ansible:

- name: Monitor Network Devices
  hosts: all
  tasks:
    - name: Check Interface Status
      cisco.ios.ios_command:
        commands:
          - show ip interface brief
      register: interfaces

    - name: Display Interface Status
      debug:
        msg: "{{ interfaces.stdout_lines }}"

Run the playbook:

ansible-playbook monitor_network.yml -i inventory.ini

Automating Security Policy Deployment Link to heading

Manually updating Access Control Lists (ACLs) can introduce misconfigurations. This Ansible playbook ensures consistent firewall rule deployment:

- name: Apply Firewall Rules
  hosts: firewalls
  tasks:
    - name: Configure ACL
      cisco.ios.ios_acl:
        name: BLOCK_EXTERNAL_ACCESS
        entries:
          - sequence: 10
            action: deny
            protocol: tcp
            src: any
            dest: 192.168.1.0/24
            dport: 22

Run the playbook:

ansible-playbook firewall_rules.yml -i inventory.ini

Troubleshooting Network Issues Link to heading

Automate troubleshooting procedures with Ansible playbooks to quickly diagnose problems:

- name: Troubleshoot Network Devices
  hosts: all
  tasks:
    - name: Check Routing Table
      cisco.ios.ios_command:
        commands:
          - show ip route
      register: routing_table

    - name: Check CPU Utilisation
      cisco.ios.ios_command:
        commands:
          - show processes cpu sorted
      register: cpu_usage

    - name: Display Troubleshooting Output
      debug:
        msg:
          - "Routing Table: {{ routing_table.stdout_lines }}"
          - "CPU Usage: {{ cpu_usage.stdout_lines }}"

Run the playbook:

ansible-playbook troubleshoot_network.yml -i inventory.ini

Automating Network Backup & Recovery Link to heading

Backup configurations regularly with Ansible, ensuring swift recovery in case of failures:

- name: Backup Network Configuration
  hosts: routers
  tasks:
    - name: Retrieve Running Config
      cisco.ios.ios_command:
        commands:
          - show running-config
      register: running_config

    - name: Store Config in Backup Directory
      copy:
        content: "{{ running_config.stdout_lines }}"
        dest: "/backups/{{ inventory_hostname }}-config.txt"

Run the playbook:

ansible-playbook backup_configs.yml -i inventory.ini