Exercise 4: Ansible Network Resource Modules - Cisco Example

Read this in other languages: uk English, japan 日本語, Français Français.

Table of Contents

Objective

Demonstration use of Ansible Network Resource Modules

Ansible network resource modules simplify and standardize how you manage different network devices. Network devices separate configuration into sections (such as interfaces and VLANs) that apply to a network service.

Network resource modules provide a consistent experience across different network devices. This means you will get an identical experience across multiple vendors. For example the VLANs module will work identically for the following modules:

Configuring SNMP on network devices is an extremely common task, and mis-configurations can cause headaches and monitoring issues. SNMP configurations also tend to be identical across multiple network switches resulting in a perfect use case for automation.

This exercise will cover:

Guide

Step 1 - Verify SNMP configuration

As you can see in the output above there is no SNMP configuration on the Cisco router.

Step 2 - Creating the Ansible Playbook

Step 3 - Examine the Ansible Playbook

Step 4 - Execute the Ansible Playbook

Step 5 - Verify VLAN configuration

As you can see, the resource module configured the Arista EOS network device with the supplied configuration. There are now five total VLANs (including the default vLAN 1).

Step 6 - Using the gathered parameter

  ---
  - name: configure VLANs
    hosts: arista
    gather_facts: false

    tasks:

    - name: use vlans resource module
      arista.eos.vlans:
        state: gathered
      register: vlan_config

    - name: copy vlan_config to file
      copy:
        content: "{{ vlan_config | to_nice_yaml }}"
        dest: "{{ playbook_dir }}/{{ inventory_hostname }}_vlan.yml"

Step 7 - Execute the gathered playbook

Step 8 - Examine the files

Takeaways

Solution

The finished Ansible Playbook is provided here for an answer key:

Complete

You have completed lab exercise 4

As stated previously only two of the resource modules parameters were covered in this exercise, but additional are available in the supplemental exercises.

In the next exercise we will start using Automation controller.

Previous Exercise | Next Exercise

Click here to return to the Ansible Network Automation Workshop