Sidebar

Ansible for Networking Engineers

Home » Webinars » Network Automation » Ansible for Networking Engineers

This webinar focuses on Ansible, the configuration management tool most commonly used by network automation professionals. It also describes YAML, the text file format used by Ansible, and Jinja2 templating language.

Last modified on 2020-12-01 (release notes)

ARF PDF MP4 ZIP

Ansible Basics

47:32 Free items Introduction

When facing a long study process, it makes sense to start with “what are we doing”, “why are we doing it” and “how is the material structured”. This section will give you these answers, and a procedure you can use to set up a simple Ansible test environment.

Introduction 16:14 2020-10-26
Webinar Structure and More Information 14:08 2020-10-26
Introduction to Ansible Collections 14:13 2020-12-01

This video describes the major changes in Ansible packaging and naming of modules, connections, and filters starting in Ansible 2.10.

2:57 Additional resources

Create a Simple Ansible Test Environment 442K 2020-12-01
Create container-based network automation environment
Run Ansible in a Docker container (by Donald Johnson)
Building a Docker network automation container (by Donald Johnson)
Sample Ansible-based network automation solutions
Full-blown VLAN-as-a-service solution
Deploying Ansible in Production 2:57 2017-07-02
Errata 174K 2019-07-29

21:32 Case Study: DMVPN Router Configuration Generation and Deployment

One of the simplest network automation use cases is the automated network generation using unified device templates. We’ll illustrate this concept with a DMVPN deployment case study that runs throughout this webinar and includes data model generation, sample device templates, and configuration deployment with Ansible.

Automated DMVPN Deployment Case Study 2.1M 2015-08-18
Case Study - Introduction 14:27 2015-08-19
Case Study - Network Design 7:05 2015-08-19

47:28 YAML and JSON

YAML is the data presentation language used extensively by Ansible playbooks and variable files. JSON is the presentation language used between Ansible and external components. It obviously makes sense to be familiar with both, and you’ll have to understand the basics of YAML to write your playbooks.

Introduction to YAML and JSON 15:54 2017-03-07
Scalar values in YAML and JSON 8:24 2017-03-07
Simple lists and dictionaries 9:44 2017-03-07
Complex Data Types 13:26 2017-03-07

Additional resources

YAML and JSON Hands-On Exercises 160K 2018-10-19
Slide deck 2.2M 2016-11-17
Source code for YAML Examples
Online YAML validator

26:51 Case Study: Building the Data Model with YAML

The second step in any automated service (or infrastructure) deployment should be a well thought-out data model (the first one should be a service definition). This section describes how you can generate a typical data model, or extract it from sample router configurations, and write it as a series of YAML files that can be used by Ansible playbooks.

Building the Data Model 9:15 2015-08-19
Case Study - Data Model for DMVPN Network 11:26 2016-02-12
Case Study - DMVPN Data Model in YAML 6:10 2015-08-19
Source code for DMVPN case study

1:20:47 Free items Jinja2 - the Templating Tool Used by Ansible

You might think you’d need a templating tool only when generating device (or service or software) configuration from templates. Not true - Ansible uses Jinja2 extensively, from evaluating expressions to specifying conditions, and finally generating text files from templates. Without understanding Jinja2 you’ll have a hard time understanding even moderately complex Ansible playbooks.

Introduction to Jinja2 14:40 2017-03-07
Complex Data Objects and Loops 22:15 2017-03-07
Variables, Macros and Includes 9:59 2017-03-07
Python Methods in Jinja2 6:08 2017-03-07
IP Address Handling 13:49 2019-09-02
Whitespace Handling in Jinja2 13:56 2018-01-31

Errata and New Features

New features in Ansible 2.4 and corrections 216K 2017-10-02

Additional resources

Jinja2 Hands-On Exercises 430K 2018-10-19
Slide deck 7.7M 2019-09-02
Use FOR-IF Construct in Jinja2 Loops
Source code for Jinja2 Examples
Dockerfile for Jinja2 renderer script
Lightweight YAML/Jinja2 parser with web UI

16:26 Case Study: Creating Device Configurations with Jinja2 Templates

Next step in our case study: after building a data model describing our DMVPN deployment, we’ll create Jinja2 templates that will be used to create device configurations.

Case Study - Preparing Configuration Templates 7:02 2015-08-19
Case Study - DMVPN Configuration Templates in Jinja2 9:24 2015-08-19
Source code for DMVPN case study

1:05:46 Free items Using Ansible

Finally it’s time to get our hands dirty and do some real automation work. You’ll learn about Ansible inventory, authentication mechanisms, Ansible modules, and the basics of Ansible playbooks - just enough to generate device configurations from templates or execute simple commands on network devices.

Introduction to Ansible 23:28 2017-05-29
Ansible Playbooks 22:19 2018-12-30
Caveat: Using registered variables with conditional task execution 3.1K 2018-12-30
Generating Configurations from Jinja2 Templates 13:29 2017-05-29
Case Study - Building Router Configurations with Ansible 6:30 2015-08-19

Additional resources

Review questions 198K 2017-05-29
Slide deck 3.2M 2016-12-05
Source code for examples used in this section

Deep Dive into Network Automation with Ansible

3:12:50 Ansible Deeper Dive

Ready for some headier Ansible stuff? Let’s explore the details of Ansible facts and variables, play and task execution (including error handling), implementing loops, working with files, and using exotic Jinja2 filters.

1:41:19 Inventory and Variables

Ansible Inventory Format 18:15 2020-10-14
Inventory Variables and Sources 18:52 2020-10-14
Inventory Variables Deep Dive 13:23 2020-10-14
Play and Task Variables 9:48 2020-10-14
Registered Facts and Extra Variables 11:06 2020-10-14
Fact Caching and Troubleshooting 15:17 2020-10-14
Special Variables 14:38 2020-10-16
Using Variables — Ansible Documentation
Special Variables — Ansible Documentation

1:02:51 Play and Task Execution

Play and Task Execution 10:04 2017-05-29
Controlling where tasks run: delegation and local actions — Ansible Documentation
Error Handling in Ansible Playbooks 6:27 2017-05-29
Error handling in playbooks — Ansible Documentation
Loops in Ansible Playbooks 21:10 2019-02-08
Loops — Ansible Documentation
Tracking Changes in Ansible Playbooks 13:21 2017-07-25
Using Check Mode for Dry Runs 11:49 2017-07-25
Validating tasks: check mode and diff mode — Ansible Documentation

28:40 Other Interesting Topics

Working with Files 17:59 2017-07-14
Exotic Jinja2 Filters 10:41 2017-06-06
Using filters to manipulate data — Ansible Documentation

Additional resources

Review questions and Hands-On Challenges 227K 2017-07-25
Slide deck 16M 2020-10-14
Source code for examples used in this section

2:03:15 Ansible Networking Modules - Executing Commands

It’s time to work with real network devices. You’ll learn how to log into network devices, execute commands on them, and get device facts and operational data.

20:53 Ansible Networking Modules Overview

Ansible Networking Modules Introduction 11:34 2019-08-07
Generic Networking Modules 9:19 2019-08-07

35:04 Connecting and Authenticating

Connecting to Network Devices 20:17 2019-08-07
Authenticating Ansible User on Network Devices 14:47 2019-08-07
Slide Deck 2.1M 2019-01-23

34:20 Executing Commands

Executing Commands on Network Devices 25:08 2019-08-07
Multi-Platform Command Execution 9:12 2019-08-07
Slide deck: Executing Commands 3.3M 2019-01-23
Source code for Executing Commands presentation

32:58 Simple Command-Based Playbooks

Collect Printouts 14:58 2019-10-05
Check Software Version 9:08 2019-10-05
Check Connectivity 8:52 2019-10-05
Slide deck: Simple Command-Based Playbooks 2.1M 2019-02-13
Source code for Command-Based Playbooks presentation

Additional resources

Review Questions and Hands-On Challenges 208K 2018-01-31
Vagrantfile and VIRL Topology used in this section
Network modules debugging and troubleshooting guide

1:19:21 Ansible Networking Modules - Getting Operational Data

Most network automation projects include gathering of operational data from network devices, be it to check device state before deploying new services, validate service deployment, or generate network maps or reports.

Some network devices can return data in machine-readable formats like XML or JSON, in many cases we still have to dismantle printouts returned by various show commands into data structures. This section describes Ansible fact gathering, working with devices that return data in JSON or XML, and parsing text printouts with TextFSM, Cisco's Genie, and TTP.

Getting Operational Data from Network Devices 18:30 2020-12-01
Gathering Network Device Facts 18:21 2020-12-01
Get Structured Data with Show Commands 21:22 2020-12-01
Parsing Show Outputs 21:08 2020-12-01
Slide deck 4.0M 2020-12-01

More Information

Source code for examples used in this section
Network Automation Text Parsing Landscape

1:47:10 Ansible Networking Modules - Managing Configurations

After managing read-only access to network devices, let’s change device configurations. We’ll cover simple configuration changes, declarative intent modules, and deploying full-blown configuration files.

Managing Network Device Configurations with Ansible 9:54 2019-10-05
Simple Configuration Changes 11:32 2019-10-05
Hierarchical Configurations 10:12 2019-10-05
Order-Sensitive Configuration Objects 10:12 2019-10-05
Deploying Configurations from Files 17:23 2019-10-29
Slide deck 24M 2019-03-11
Source code for configuration management examples

24:30 Other Device Configuration Tasks

Gathering and Comparing Configurations 12:14 2019-10-29
Replacing Configurations 6:31 2019-10-29
Saving Running Configuration 5:45 2019-10-29
Source code for "configuration replace" functionality

23:27 Declarative Configuration Modules

Declarative Configuration Modules 15:14 2019-10-29
Improving Performance of Declarative Configuration 8:13 2019-10-29
Slide Deck 2.7M 2019-03-17
Source code for declarative configuration modules
How wrong indent combined with Ansible networking modules can trash your device configuration (by Patrick Ogenstad)

Additional resources

Vagrantfile and VIRL Topology used in this section
Review Questions and Hands-On Challenges 247K 2017-06-06

33:28 Creating Reusable Code

You want to reuse excellent bits of your code in multiple projects and package them as ready-to-use libraries, right? Let’s dig into playbook- and play-level includes, looping over included modules (which is the closest you can get to subroutine calls in Ansible), and Ansible roles.

Play and Task Includes 12:36 2017-07-02
Task Includes and Loops 6:47 2017-07-02
Ansible Roles 14:05 2017-07-02

Additional resources

Review Questions 156K 2017-07-12
Slide deck 1.9M 2017-03-07
Sample playbooks for Ansible 'include' functionality
Ansible roles examples
Using Ansible roles to build DMVPN router configurations

Further reading

Using Ansible roles to manage large-scale infrastructure

49:24 Extending Ansible

Ansible is a powerful tool, but it shouldn’t be used as a generic-purpose programming language, so don’t try to use it as a Swiss Army Chainsaw - complex tasks should be implemented with a real programming language using Ansible callbacks, modules, external components, or (simplest possible option) Jinja2 filters and tests.

Extending Ansible 9:13 2017-06-30
Dynamic Inventory and Hosts 10:15 2017-06-30
Callback Plugins 9:05 2017-06-30
Jinja2 Filters and Tests 20:51 2017-06-30

Additional resources

Review Questions and Hands-On Exercises 167K 2017-07-13
Slide deck 1.8M 2017-03-07
Sample playbook using roles
Sample Jinja2 filters
Ansible Custom Inventory Plugin - a hands-on, quick start guide

46:23 Debugging Ansible Playbooks

Debugging Ansible playbooks and Jinja2 templates and expressions could turn into an excruciating experience. The guidelines and hints you'll get in this section will make your debugging process easier and faster.

Debugging Ansible Playbooks 15:40 2017-12-12
Snapshot Ansible Variables 8:52 2017-12-12
Debugging Jinja2 Templates 9:28 2017-12-12
Common Pitfalls 12:23 2017-12-12
Slide Deck 2.5M 2017-11-08

Beyond Ansible

1:01:01 Using NAPALM with Ansible

Ansible includes low-level network device modules - you have to use a different module for every vendor or operating system. NAPALM provides an abstraction library that gives you a uniform interface to device configurations, operational data, and even fully-automated device state validation… with an easy-to-use set of Ansible modules.

What Is NAPALM 19:10 2018-04-17
NAPALM Ansible Modules 14:33 2018-04-17
Fully-Automated Verification 11:25 2018-04-17
Hands-On Examples and Playbooks 15:53 2018-04-17

Additional resources

Slide deck 583K 2017-05-21
Source code for examples used in this section

33:00 Validation Network Device State with NAPALM

NAPALM includes state validation functionality that compares the actual state of a network device (as retrieved with NAPALM getters) with the desired state defined in a YAML file and reports the discrepancies. The same functionaliy can be used independently or from within an Ansible playbook.

Introduction to Deployment Validation with NAPALM 3:46 2018-05-11
NAPALM Validation Overview 12:21 2018-05-11
Using NAPALM-based Deployment Validations with Ansible 16:53 2018-05-11
Slide deck 20M 2018-02-02
Source code for examples used in this section

Examples and Case Studies

47:09 Sample Ansible Playbooks

This section contains sample Ansible playbooks. Every subsection has a video explanation, optional writeup in PDF format, and link to the source code.

15:19 Collect SSH keys from managed devices

Collect SSH Keys 15:19 2017-06-17
Source code for Ansible playbook
VIRL topology used in this example

12:49 Store Device Configurations to Git Repository

Store Device Configurations to Git Repository 12:49 2017-06-17
Source code for Ansible playbook
VIRL topology used in this example

19:01 Generate network topology graph from LLDP neighbor information

Create Network Diagram from LLDP Neighbor Information 19:01 2017-07-14
Source code for Ansible playbooks
Vagrant-based Arista EOS lab used in this example

1:12:41 WAN Services Deployment Case Study

This case study describes WAN services deployment process including:

  • Generating device-focused data model from network-wide infrastructure data model;
  • Validating fabric connectivity with LLDP
  • Configuring OSPF, BGP and MP-BGP
  • Provisioning MPLS/VPN services
Case study introduction 3:14 2017-07-14
Create Device Data Model from Infrastructure Data Model 23:30 2017-07-14

In the data model part of the case study you'll learn:

  • The importance of using network-wide data model when describing your network infrastructure;
  • The benefits of using device-focused data model when creating configuration templates;
  • How to generate YAML data files with Jinja2 templates
  • How to use Ansible playbook to create inventory file and host variables from a network-focused data model
Validate Fabric Connectivity 22:56 2017-07-14

After building the network-centric data model, we'll use it to validate fabric connectivity using information gathered with LLDP. You'll also learn how to translate data models on-the-fly within an Ansible playbook.

Configure and Validate OSPF Routing 23:01 2017-09-03

In the final part of the case study, we'll build OSPF configurations, figure out what changes they would cause on the fabric devices, deploy them, and finally verify that OSPF routing process sees the expected neighbors on fabric links.

Additional resources

Source code for data model and fabric connectivity videos

Reference material

Solutions for Hands-On Exercises

Solutions for YAML and JSON Hands-On Exercises 238K 2017-06-27
Solutions for Jinja2 Hands-On Exercises 705K 2017-06-29

Even More Ansible Playbooks

This section contains sample Ansible playbooks from ipSpace.net GitHub repositories.

Extract DHCP pools from Cisco IOS routers or switches
Configure DHCP pools and cleanup stale entries
Extract network topology (including network graph) from interface Description-to-Links
Create a fabric data model from interface descriptions
Create and deploy DMVPN configurations on Cisco IOS routers
Deploy approved configurations from Git repository to candidate configurations on network devices
Simple compliance check framework
Create device uptime report from SNMP facts
Transform infrastructure data model into device-focused data model
Configure and verify OSPF neighbors
Configure and verify BGP neighbors
Configure VRFs and VPNv4 address families from list of customer services

Reference: Building a networking automation lab

This section contains links to various documents describing how you can build your own network automation lab using either physical or virtual devices.

Build Your Own Automation Lab

This document should help you get started - it discusses numerous lab setup options, including sample lab setups created by attendees of our network automation course.

Running Ansible in a Vagrant-controlled Virtual Machine

Vagrant uses poorly-documented internal virtual networks. This document describes the various ways of establishing connectivity between Ansible running in a Vagrant-controlled virtual machine and other virtual machines controlled by the Vagrant instance.

Create Ansible Inventory Files from Vagrant SSH Configuration

This simple tool creates Ansible inventory files from Vagrant port forwarding printouts and supports running Ansible on the host or in a Vagrant-controlled VM. Highly recommended when running Vagrant with VirtualBox.

Sample Vagrant-based topologies

Vagrant-controlled Ansible VM used with VIRL
Vagrant-controlled Ansible and Juniper vSRX VMs used with VIRL
Arista vEOS leaf-and-spine topology

This section contains a collection of links you might find useful when building your own lab in a non-standard way. Note: you're on your own ;)

Creating your own IOS-XR Vagrant box
Building your own CSR1000v Vagrant box
Using The Libvirt Provider With Vagrant
Cisco CSR 1000v Vagrant Libvirt Box Install
Cisco IOSv Vagrant Libvirt Box Install
Cisco IOSXRv Vagrant Libvirt Box Install
%arc%
%arc%
%arc%
You started this section on %started% Mark completed