Course Code: bspanspyth
Duration: 35 hours
Prerequisites:

Bespoke course for Simon Earp

Course Outline:

Part I: Python for Networking Engineers
The first part of class focuses on teaching student how to program with Python using
100% networking-oriented practical examples. It is much easier to learn programming
when networking professionals write code that solves networking problems, so students
will write code to solve clearly understood problems, with the class focused on writing
Python and not trying to understand the problem. All labs will use programming
examples to solve networking problems.

Day 1 - Python Fundamentals
1. Conditionals
2. Loops
3. Functions
4. Data Types and Variables
5. Scopes and Namespaces
6. Classes and Objects
7. Methods, decorators, etc...
8. NAPALM

Day 2 - Continuing Python Fundamentals
1. Exception Handling
2. Regular Expressions
Serialization of data
Files

  • YAML
  • JSON
  • XML

3. NETCONF

  • http://jedelman.com/home/netconf-and-the-ncclient/

Python Labs
The hands-on labs in this section will be based on Python scripts that students will write
and deploy. All code will be networking-relevant, or emphasize basic coding skill sets all
programmers need to know.
1. Student Setup for Introduction to Network Automation with Python and Ansible Labs

2. Using vim
3. Using & Installing Python
4. The Shebang Line
5. Using Print() to understand Input / Output
6. Using while, if, elif, else
7. Troubleshooting while, if, elif, else
8. Program a CIDR to Subnet Mask Calculator
9. Understanding Python Lists
10.Using for, range, format, if, elif, else
11.for loops and range()
12.Defining Functions
13.Working with from and import
14.Writing your own script with if, elif, and else statements
15.Using Python to Create an OpenStack Permissions File
16.Writing a Python Application to Parse Keystone Log File for Failed Auth Attempts
17.Python Package Management System
18.Using Python to get at your Network Interfaces
19.JSON to YAML Converter, Wireshark, and SIP
20.RESTful Interfaces with Python and etcd
21.Construct a SimpleHTTPServer and HTTP Client
22.Use RegEx to Check Your External IP Address
23.Use RegEx to Search Text

Part II: Ansible


Day 3
We begin with an introduction to Ansible, making it clear how Ansible solves DEVOPs
problems. The first step is to learn how to get Ansible to connect to hosts. A popular
thing to say is that Ansible is “clientless”, making it sound like it is simple to connect to a
remote host when in fact for most people, connecting to a remote host can be a
challenging task for the uninitiated. The labs focus on teaching RSA connectivity so that
Ansible will connect to remote hosts. With a clear understanding of Ansible connectivity
established, the class moves on to a basic understanding of CLI commands and practice
using Ansible to connect to hosts and issue ad-hoc commands.
1. Ansible Overview
2. Ansible Inventory
3. Ad hoc commands

Day 3 Labs
1. SSH 101 - client and server configs (/etc/sshd_config and /etc/ssh_config)
2. SSH 101 - users and passwords + linux command line
3. RSA Connectivity:

  • SSH 101 - RSA key generation
  • SSH 101 - authorized_keys file + passwordless login
  • SSH 101 - copy-id and ~/.ssh/config

4. Users 101 - users and groups
5. Users 101 - sudo, /etc/sudoers, visudo - make someone a sudoer
6. Users 101 - passwordless sudoers - now make that user a passwordless sudoer
7. Pip 101 - list, install, freeze, etc
8. Install different versions of ansible with pip
9. Install dependencies on host (ad hoc raw)
10.Set up a simple host file and ad hoc ping (-i hosts file))
11.Set up a group and group of groups and ping, also ping all
12.Challenge labs

  • Ad hoc to host with incorrect user (student sees error and fixes username)
  • Ad hoc to host with ssh password (avoid prompts with cli arg)
  • Ad hoc to host with bad RSA key (fix with new one that works)
  • Ad hoc to host with password sudoer (avoid prompts with cli arg and fix with

visudo)
13.Ad hoc a gather fact command
14.Ad hoc a shell command that does something verifiable

Day 4
Topics on day 4 focus on learning how to read and run playbooks helping students learn
how to be an Ansible administrator. Students will learn how playbooks organize the code
that was written on day-one, encode it in YAML and letting Ansible do real work. The lecture
portion will be covered in the morning, with hands on labs being conducted during the
afternoon. At the end of the day you will be able to read playbooks as well as understand
how to modify the host file and variables to make Ansible perform site-specific tasks.
1. YAML
2. Writing a simple Playbook
3. Ansible Templates and Jinja2
4. Ansible Modules you need to know
5. NAPALM and napalm-ansible
Day 4 Labs
6. yaml dictionary (--extra_vars and show in debug module)
7. yaml list (--extra_vars and show in debug module)
8. Set up ansible.cfg file to simplify cli args
9. A simple multi-step all-in-one playbook
10.A playbook with inventory file, include file, main file, and var file
11.Ansible Modules - Template

  • A jinja2 template fill-in-the-blank ini file
  • A jina2 variable example
  • A jinja2 filter example
  • A jinja2 test (if/then) example

12.Ansible Modules - Command / Shell
13.Ansible Modules - Copy
14.Ansible Modules - Apt
15.Ansible Modules - Yum
16.Ansible Modules - Get_url
17.Ansible Modules - File (create directories)
18.Ansible Modules - quiz via documentation, 10 scavenger hunts
19.Ansible Modules - Start/Stop/Restart (forced within playbook)
20.Ansible Handlers - Restart service at the end of playbook (nginx?, networking?)
21.Ansible Handlers - lots of contrived examples with debug tasks in handlers
22.Napalm installation (pip)
23.Napalm examples without ansible
24.Napalm-ansible ansible module Instal

  • Ansible Modules - Napalm_get_facts
  • Ansible Modules - Napalm_install_config
  • Ansible Modules - Napalm_validate

Day 5
Focus on writing playbooks helping students become Ansible developers. Students will
learn best practices as well as more advanced applications such as conditional
processing and looping, both of which require an understanding of Ansible variables. Due
to the modularity of Ansible, which is discussed on day 2, you will branch out and use
Ansible to configure clouds as well as advanced networking configurations. We will finish
the day with a review of Ansible Tower, using the latest version of Tower, namely AMX.
1. Ansible OpenStack Configuration
2. Ansible variables, conditional and looping tasks
3. Dynamic Inventory
4. Roles
5. Playbook Best practices
6. NTC (network-to-code) Modules
7. Ansible Tower / AWX Essentials

Day 5 Labs
1. Install openstack dependencies (shade via pip and clouds.yml)
2. Boot and configure an openstack instance
3. Advanced Playbooks - Variables and loops
4. Advanced Playbooks - Complex variable in a loop

5. Advanced Playbooks - A task using When based on a register variable from a
previous task (Idempotent example that also shows conditional execution of a task
6. Dynamic Inventory - Something that uses openstack.py
7. Advanced Playbooks - A multi-role scenario where we boot a web service using
roles, templates and everything else we can think of. The capstone event
8. Install and run an AWX server