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-04-05 (release notes)


26:12 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 12:53 2017-05-29
Webinar Structure and More Information 10:22 2017-05-29

2:57 Additional resources

Create a Simple Ansible Test Environment 432K 2018-10-26
Run Ansible in a Docker container
Building a Docker network automation container
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

1:51:05 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.

Ansible Variables 19:34 2017-05-29
Using Variables — Ansible Documentation
Play and Task Execution 10:04 2017-05-29
Delegation, Rolling Updates, and Local Actions — Ansible Documentation
Error Handling in Ansible Playbooks 6:27 2017-05-29
Error Handling In Playbooks — Ansible Documentation
Working with Files 17:59 2017-07-14
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
Check Mode (“Dry Run”) — Ansible Documentation
Exotic Jinja2 Filters 10:41 2017-06-06
Filters — Ansible Documentation

Additional resources

Review questions and Hands-On Challenges 227K 2017-07-25
Slide deck 2.7M 2017-06-27
Source code for examples used in this section

3:19:40 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

1:16:25 Getting Operational Data

The videos in this section still use connection: local and provider dictionary. Please check the Connecting and Authenticating section describing networking features in newer Ansible releases.

Getting Operational Data from Network Devices 16:55 2018-01-31
Gathering Network Device Facts 14:51 2018-01-31
Get Structured Data with Show Commands 16:24 2018-01-31
Parsing Show Outputs 22:20 2018-01-31
Use SNMP to Get Device Facts 5:55 2017-01-04
Slide deck 4.9M 2017-11-30
Source code for parse_cli examples used in this section

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

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

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

Sample Ansible Playbooks

This section contains sample Ansible playbooks from GitHub repositories.

Collect SSH keys from managed devices
Store Device Configurations to Git Repository
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
Generate network topology graph from LLDP neighbor data
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
You started this section on %started% Mark completed