Network automation lab 11 of 27
Jinja2 templates and a YAML source of truth
Generate complete router configurations from a YAML source of truth with Jinja2: loops, conditionals, whitespace control, built-in and custom filters, macros, template inheritance and strict undefined variables, then deploy them to three routers and prove OSPF and the intended path.
Run this lab
It needs Lite: its 4 nodes are set to 4 vCPU and 2,560 MB in total. That fits the free demo too.
In your workspace: Shared, then Network Automation - CCNA and CCNP Automation guided labs, then 11 - Jinja2 templates and a YAML source of truth
- Level
- Intermediate
- Time
- About 80 minutes
- Nodes need
- 4 vCPU, 2,560 MB
- Smallest plan
- Lite
The scenario
Kestrel Freight is rolling out the same router design to dozens of depots, so nobody will type configurations by hand any more. Intent lives in one file, the source of truth sot.yaml: sites, NTP and syslog servers, loopbacks, links and OSPF settings. Jinja2 templates turn it into complete configurations. Today you'll build the templates for the northern triangle (r1, r2 at Leeds and r3 at York), generate the three configurations, deploy them, and prove the result, including a deliberate OSPF cost on r2 that should steer its traffic to r3 through r1.
| Router | Site | Loopback0 | Links (from sot.yaml) |
|---|---|---|---|
| r1 | LDS Leeds | 10.255.0.1/32 | Gi0/1 10.1.12.1/30 → r2 · Gi0/2 10.1.13.1/30 → r3 |
| r2 | LDS Leeds | 10.255.0.2/32 | Gi0/1 10.1.12.2/30 → r1 · Gi0/2 10.1.23.1/30 → r3 (OSPF cost 50) |
| r3 | YRK York | 10.255.0.3/32 | Gi0/1 10.1.13.2/30 → r1 · Gi0/2 10.1.23.2/30 → r2 · Gi0/3 spare, shut |
The routers start with only their management address (Gi0/0, 10.10.20.11–13). Files in ~/lab: sot.yaml, templates/ (base.j2, macros.j2, router.j2, all TODOs), render.py (filters to write), deploy.py and check.py (ready). Login netops / NetOps-Lab1.
What you’ll practise
- Render Jinja2 templates with variables, loops and conditionals, and control whitespace
- Use built-in filters and write custom filters for IP address arithmetic
- Structure templates with macros, includes and inheritance (extends and blocks)
- Catch missing data with StrictUndefined instead of generating silently broken configuration
- Build Day-0-style full configurations from a source of truth, deploy them and verify the result
The tasks
- First templates
- Loops, conditionals and whitespace
- Filters, including your own
- A macro for interfaces
- Template inheritance
- Make missing data fail loudly
- Render the configurations (Day 0)
- Deploy and prove the design
The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.
Topology and devices
The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.
Every link, as text
- devbox
eth0to Mgmt (network) - r1
Gi0/0to Mgmt (network) - r2
Gi0/0to Mgmt (network) - r3
Gi0/0to Mgmt (network) - r1
Gi0/1to r2Gi0/1 - r1
Gi0/2to r3Gi0/1 - r2
Gi0/2to r3Gi0/2
| Node | Device | Image in Add Node | Set to |
|---|---|---|---|
| devbox | EVE-NG GUI server (Docker) | eve-gui-server:latest | 1 vCPU, 1,024 MB |
| r1 | Cisco IOSv | vios-adventerprisek9-m.spa.159-3.m9 | 1 vCPU, 512 MB |
| r2 | Cisco IOSv | vios-adventerprisek9-m.spa.159-3.m9 | 1 vCPU, 512 MB |
| r3 | Cisco IOSv | vios-adventerprisek9-m.spa.159-3.m9 | 1 vCPU, 512 MB |
How to open this lab
Sign in to your workspace at
lab.cloudlabbox.com.In File Manager, open Shared, then the folder
Network Automation - CCNA and CCNP Automation guided labs.Open
11 - Jinja2 templates and a YAML source of truthand start its nodes, then open Lab Tasks for the scenario and the steps.
The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.
More Network automation labs
Related labs in other courses
CloudLabBox is independent of Cisco. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.