Network Automation with Python and Ansible Part 2

Course Overview

Suggested prerequisite:
Network Automation with Python and Ansible: Part 1

This course assumes a basic proficiency with Python. The first day and a half are geared towards reviewing key Python topics critical to deep-diving into Ansible. Ansible is the focus of this course, so students will leave this course with a proficiency, ready to use Ansible within a corporate environment. All labs will use programming examples to solve networking problems.

python course cover image

Course Outline: Network Automation with Python and Ansible Part 2

5 Days with Hands-on Labs


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
  1. NETCONF

 

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. Getting started in the student environment
  2. Using vim
  3. Review of built-in functions
  4. Writing your own functions
  5. Using while, if, elif, else
  6. Troubleshooting while, if, elif, else
  7. Manipulating IP with Python
  8. Python Lists
  9.  Using for, range, format, if, elif, else
  10.  for loops and range()
  11.  Working with from and import
  12.  Writing your own script with if, elif, and else statements
  13.  Using Python to Output Files for use
  14.  Exploring / Reviewing pip
  15.  Using Python to get at your Network Interfaces
  16.  JSON to YAML Converter, Wireshark, and SIP
  17. RESTful Interfaces with Python and etcd
  18. Python for Web Servers and Clients
  19. Working with RegEx to get at IP addresses
  20. Working with RegEx to find the ‘text you want’

 

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 is a nightmare for the uninitiated. You will run hands on labs that will clearly show RSA connectivity so that Ansible will connect to remote hosts. With a clear understanding of Ansible connectivity established, we establish 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 4 This is the day we learn how to read and run playbooks.  In other words, today you will learn how to be an Ansible administrator, not a developer. That means we must learn how playboks organize the things we did on day-one, encode them in YAML and make Ansible do real work. The lecture portion will be covered in the morning, with hands on labs dominating the afternoon.  At the end of this day, you will be able to read playbooks with understanding. On this day you will 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 5 This is the day you will learn how to write playbooks. In other words, today you will learn how to become an Ansible developer.  You will learn best practices and then do 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 became clear on day 2, you will branch out and use ansible to configure clouds and even 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

 

 

Ansible Labs

While students are encouraged to do all the labs, but normally ONLY A PORTION OF THEM is required. The teacher will tell you which labs are mandatory based on the level of skill you wish to develop. Labs will be available 24 x 7 for the duration of the class and can remain available for the following week on request.

 

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 Labs

  1. yaml dictionary (--extra_vars and show in debug module)
  2. yaml list (--extra_vars and show in debug module)
  3. Set up ansible.cfg file to simplify cli args
  4. A simple multi-step all-in-one playbook
  5. A playbook with inventory file, include file, main file, and var file
  6. 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
  1. Ansible Modules - Command / Shell
  2. Ansible Modules - Copy
  3. Ansible Modules - Apt
  4. Ansible Modules - Yum
  5. Ansible Modules - Get_url
  6. Ansible Modules - File (create directories)
  7. Ansible Modules - quiz via documentation, 10 scavenger hunts
  8. Ansible Modules - Start/Stop/Restart (forced within playbook)
  9. Ansible Handlers - Restart service at the end of playbook (nginx?, networking?)
  10. Ansible Handlers - lots of contrived examples with debug tasks in handlers
  11. Napalm installation (pip)
  12. Napalm examples without ansible
  13. Napalm-ansible ansible module Instal
    1. Ansible Modules - Napalm_get_facts
    2. Ansible Modules - Napalm_install_config
    3. Ansible Modules - Napalm_validate

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

Alta3 Research

Network Automation with Python and Ansible Part 2


Duration: 5 Days (instructor-led)

Delivery: Onsite or Instructor-led Virtual

Price:
Onsite: Contact us for group quotes