Bookmark this page

Chapter 5. Automating Simple Network Operations

SectionGathering Network Information with Ansible
SectionObjectives
SectionNaming of Common Network Device Modules
SectionNaming of Other Network Device Modules
SectionModules that Gather Facts on Network Devices
SectionModules that Run Commands on Network Devices
SectionModules that Configure Network Devices
SectionModules that Configure Layer 3 Interfaces
SectionGathering Facts
SectionExploring vyos_facts and ios_facts
SectionExpanding the Result Set
SectionSelecting Facts
SectionInvestigating Fact Selection
Guided Exercise: Gathering Facts
Guided Exercise: Viewing System Settings
Configuring Network Devices
Objectives
Backing Up Device Configurations
Backing up Configurations on Demand
Backing Up Configurations With Playbooks
Guided Exercise: Backing Up Network Device Configurations
Configuring the Host Name
Objectives
Configuring Network Devices
Guided Exercise: Configuring the Host Name
Configuring System Settings
Objectives
Contextualizing Configuration Statements
Guided Exercise: Configuring System Settings
Generating Configuration Settings from Jinja2 Templates
Objectives
Updating With Other Modules
Sourcing Statements From a File
Generating Configurations With Templates
Configuring Directly From Templates
Guided Exercise: Configuring From Templates
Guided Exercise: Configuring Settings From Templates
Enabling and Disabling Interfaces
Objectives
Selecting an Interface Module
Guided Exercise: Bouncing an Interface
Guided Exercise: Bouncing Specified IOS Interfaces
Reinitializing Layer 3 Interfaces
Objectives
Enumerating Interfaces
Introspecting Interfaces
Converting Output to List
Reinitializing Layer 3
Guided Exercise: Reinitializing Layer 3 on VyOS Devices
Provisioning the Start-up Network
Objectives
Provisioning the Start-up Network
Guided Exercise: Provisioning the Start-up Network
Provisioning Spine and Leaf Devices
Objectives
Provisioning the Expansion Network
Guided Exercise: Provisioning Spine and Leaf Devices
Setting Parameters with Ansible Tower Surveys
Objectives
Extending Parameterizing Automation
Providing Extra Data for Playbooks
Guided Exercise: Setting Parameters with Ansible Tower Surveys
Lab: Automating Simple Network Operations

Abstract

Goal Automate simple operations on network devices
Objectives
  • Interrogate network devices with automation.

  • Back up device configurations.

  • Perform simple actions using playbooks.

  • Apply simple changes using playbooks.

Sections
  • Gathering Network Information with Ansible (and Guided Exercises)

  • Configuring Network Devices (and Guided Exercise)

  • Configuring the Host Name (and Guided Exercise)

  • Configuring System Settings (and Guided Exercise)

  • Generating Configuration Settings from Jinja2 Templates (and Guided Exercises)

  • Enabling and Disabling Interfaces (and Guided Exercises)

  • Reinitializing Layer 3 Interfaces (and Guided Exercise)

  • Provisioning the Start-up Network (and Guided Exercise)

  • Provisioning Spine and Leaf Devices (and Guided Exercise)

  • Setting Parameters with Ansible Tower Surveys (and Guided Exercise)

Lab

Automating Simple Network Operations

Gathering Network Information with Ansible

Objectives

After completing this section, you should be able to:

  • Gather data about network devices and networks using facts, ad hoc commands, and playbooks.

  • Selectively target and extract information.

Naming of Common Network Device Modules

Ansible provides many platform-specific modules engineered to make it easier to automate the management of networking devices. The names of these modules generally follow a common pattern. These are four common families of modules:

  • Gather facts from networking devices using the *os_facts family of Ansible modules.

  • Issue commands to networking devices using the *os_command family of Ansible modules.

  • Configure networking devices using the *os_config family of Ansible modules.

  • Configure layer 3 interfaces using the *os_l3_interface family of Ansible modules.

Naming of Other Network Device Modules

The *os_facts, *os_commands, *os_config, and *os_l3_interface families of modules represent a small part of the very large collection of *os_* modules that make it easier to manage networking devices.

Use the ansible-doc -l command to explore what is available.

Modules that Gather Facts on Network Devices

The modules in the *os_facts family are used to gather facts from networking devices:

  • cnos_facts

  • edgeos_facts

  • enos_facts

  • eos_facts

  • ios_facts

  • junos_facts

  • nxos_facts

  • vyos_facts

Modules that Run Commands on Network Devices

The modules in the *os_command family are used to issue commands to networking devices:

  • aireos_command

  • cnos_command

  • edgeos_command

  • enos_command

  • eos_command

  • ios_command

  • junos_command

  • nxos_command

  • sros_command

  • vyos_command

Modules that Configure Network Devices

The modules in the *os_config family are used to configure networking devices:

  • aireos_config

  • edgeos_config

  • enos_config

  • eos_config

  • fortios_config

  • ios_config

  • junos_config

  • nxos_config

  • sros_config

  • vyos_config

Modules that Configure Layer 3 Interfaces

The modules in the *os_l3_interface family are used to configure layer 3 interfaces on networking devices:

  • eos_l3_interface

  • ios_l3_interface

  • junos_l3_interface

  • nxos_l3_interface

  • vyos_l3_interface

Gathering Facts

  • Each networking platform has an *os_facts module.

  • The Lab Network has VyOS and IOS devices, so you will use the vyos_facts and ios_facts modules.

Exploring vyos_facts and ios_facts

You can use an ad hoc command to show which facts are returned by default.

Now that you are somewhat familiar with Ansible Vault, you can use encrypted files to store all sensitive data, including passwords.

The following command displays the default set of facts returned by the vyos_facts module:

[user@host ~]$ ansible -i inventory --ask-vault-pass -m vyos_facts vyos

The following command displays the facts provided by default by the ios_facts module:

[user@host ~]$ ansible -i inventory --ask-vault-pass -m ios_facts ios

Expanding the Result Set

How many facts can you gather using vyos_facts and ios_facts?

The following command displays all facts supported by the vyos_facts module:

$ ansible -i inventory --ask-vault-pass -m vyos_facts spine01 \
> -a 'gather_subset=all'

The following command displays all facts supported by the ios_facts module:

$ ansible -i inventory --ask-vault-pass -m ios_facts cs01 -a 'gather_subset=all'

Selecting Facts

The gather_subset=all option returns a lot of information. The following playbook displays only specific pieces of information when run. The vyos_facts module was used. Note that variables are automatically registered by the facts module.

[user@host ~]$ cat vyos-some-facts1.yml
---
- name: a play that gathers some facts and displays them
  hosts: vyos

  tasks:
    - name: invoke vyos_facts
      vyos_facts:
        gather_subset: default

- debug:
    msg:
      - "Host name: {{ ansible_net_hostname }}"
      - "    Model: {{ ansible_net_model }}"
      - "  Version: {{ ansible_net_version }}"
      - "SerialNum: {{ ansible_net_serialnum }}"

Investigating Fact Selection

The following example runs the playbook to gather some facts.

[user@host proj]$ ansible-playbook -l leaf01 vyos-some-facts1.yml

PLAY [a play that gathers some facts and displays them] **********************

TASK [invoke vyos_facts] *****************************************************
ok: [leaf01]

TASK [debug] *****************************************************************
ok: [leaf01] => {
    "msg": [
        "Host name: vyos"
        "    Model: VMware"
        "  Version: VyOS"
        "SerialNum: VMware-56"
    ]
}

PLAY RECAP *******************************************************************
leaf01                      : ok=2    changed=0    unreachable=0    failed=0
Revision: do457-2.5-4693601