Network automation: Ansible, Netmiko and templates
You move hand-made configuration into templates, inventory and version control, and manage dozens of devices consistently and reversibly with Ansible and Python.
Level 401 · 18 lessons · 15 practice labs
Lessons
Foundations
- Why automate: consistency and speed
- Inventory and variables
- Configuration templates with Jinja2
- Short task: generate configurations for ten routers
With Python
- Sending commands over SSH with Netmiko
- Reading device facts with NAPALM
- Parsing command output: TextFSM
- Introduction to NETCONF and RESTCONF
- Short task: back up the configuration of every device
With Ansible
- Managing network devices with Ansible
- Idempotent changes
- Showing diffs and dry runs
- Keeping network configuration in Git
- Short task: roll a new VLAN out to every switch
Verification
- Pre- and post-change checks
- Catching configuration drift
- Short task: find a manual change and roll it back
Wrap-up
- Capstone: an automated, verified and reversible network change
Practice labs
- Five routers from one template: Generate configuration files for five routers from the given YAML inventory with a Jinja2 template and show with diff that one matches the hand-written example.
- The template produces broken configuration: Fix the template that produces broken output due to a missing variable and a wrong loop, add a check that validates the inventory before rendering and show bad input being rejected.
- All of a new branch’s configuration in one command: Write a tool for Kuzey Logistics that generates router, switch and DHCP configurations from a branch name and address block, then apply the output to lab devices and show it working.
- The same command on every device: Connect to every device in the inventory with Netmiko, fetch the interface summary and save the results to separate files named after each device.
- The backup script hangs on one device: Add timeouts, error handling and a summary report to the script that backs up every device’s configuration, and show it no longer stops at the unreachable device.
- Nightly backups into Git: Write a script that pulls device configurations in parallel, commits them to Git with a meaningful message when something changed and skips empty commits for unchanged devices, and show the behaviour over two runs.
- Turn command output into a table: Parse the router’s neighbour table output with a TextFSM template and save the result as CSV.
- Build the device inventory automatically: Read model, software version, serial number and interface count from every device with NAPALM and produce an inventory report flagging those on old versions.
- Config versus state over NETCONF: Pull both configured and operational interface state from the devices over NETCONF, write a script that finds interfaces that are administratively up but not working and show the result.
- The same NTP setting on every device: Apply the NTP server setting to every lab device with Ansible and show that the second run changes nothing.
- Dry-run the new VLAN first: Try the playbook that adds a new VLAN to every switch with --check and --diff, find and fix an unexpected difference, then run it for real.
- A verified, reversible change: Build a change workflow with pre- and post-checks that restores the previous configuration when the post-check fails, and demonstrate the rollback with a deliberately broken change.
- What changed between yesterday’s backup and today?: Compare the device’s current configuration with the last backup in Git, find the manual change and work out from the log who made it and when.
- A drift report for the whole network: Write a script that compares every device in the inventory with the intended configuration and lists the differences per device and line.
- Find the manual change and roll it back: Find the drift on three devices in the Saltmarsh Fisheries network, decide which one is an emergency fix and fold it into the source, roll the others back with automation and show zero difference at the end.
About this course
You move hand-made configuration into templates, inventory and version control, and manage dozens of devices consistently and reversibly with Ansible and Python.
What you will learn
- Foundations
- With Python
- With Ansible
- Verification
- Wrap-up
Prerequisites
You should have practised the topics of the same path up to level 301.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 401; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.