Chapter 7. Hands-on Look at Using Ansible for Network Automation

In the previous chapter, a general overview of Ansible terminology was provided. This covered many of the specific Ansible terms, such as playbooks, plays, tasks, modules, and inventory files. This section will continue to provide working examples of using Ansible for network automation, but will provide more detail on working with modules to automate a few different types of devices. Examples will include automating devices from multiple vendors, including Cisco, Arista, Cumulus, and Juniper.

The examples in this section assume the following:

  • Ansible is installed.

  • The proper APIs are enabled on the devices (NX-API, eAPI, NETCONF).

  • Users exist with the proper permissions on the system to make changes via the API.

  • All Ansible modules exist on the system and are in the library path.

Note

Setting the module and library path can be done within the ansible.cfg file. You can also use the -M flag from the command line to change it when executing a playbook.

The inventory used for the examples in this section is shown in the following section (with passwords removed and IP addresses changed). In this example, some hostnames are not FQDNs as they were in the previous examples.

Inventory File

[cumulus]
cvx  ansible_ssh_host=1.2.3.4 ansible_ssh_pass=PASSWORD

[arista]
veos1

[cisco]
nx1  hostip=5.6.7.8 un=USERNAME pwd=PASSWORD

[juniper]
vsrx hostip=9.10.11.12 un=USERNAME pwd=PASSWORD
Note

Just in case you’re wondering ...

Get Network Automation with Ansible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.