Exercise 4: Ansible Network Resource Modules - Cisco Example

Read this in other languages: uk English

Table of Contents

Table of Contents


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 snmp_server 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:


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 SNMP configuration

As you can see, the resource module configured the Cisco IOS-XE network device with the supplied configuration. There are now two total SNMP communities.

Step 6 - Using the gathered parameter

  - name: Retrieve SNMP config
    hosts: cisco
    gather_facts: false


      - name: Use SNMP resource module
          state: gathered
        register: snmp_config

      - name: Copy snmp_config to file
          content: "{{ snmp_config | to_nice_yaml }}"
          dest: "{{ playbook_dir }}/{{ inventory_hostname }}_snmp.yml"
          mode: "644"

Step 7 - Execute the gathered playbook

Step 8 - Examine the files

  $ cat rtr1_snmp.yml
  changed: false
  failed: false
      -   acl_v4: acl_uq
          name: ChapelHill-community
          rw: true
      -   acl_v4: acl_uq
          name: Durham-community
          rw: true
      location: Durham
      packet_size: 500



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


You have completed this lab exercise.

Click here to return to the Ansible Network Automation Workshop