Nornir Network Automation: Creating Your First Runbook (show version)
In this guide, we’ll walk through building a simple Nornir runbook that sends the show version command to a network topology running Arista vEOS routers in an EVE-NG lab. Let’s get started!
Lab Environment
- Ubuntu Dev Box (Dev environment):
192.168.1.21 - EVE-NG Server (Topology host):
192.168.1.254 - Routers:
R1:192.168.1.22R2:192.168.1.23R3:192.168.1.24
All devices are Arista vEOS routers.
Step 1: Setup Inventory & Config Files
Inside your working directory (~/automation/), define these YAML files:
config.yaml
inventory:
plugin: SimpleInventory
options:
host_file: "hosts.yaml"
group_file: "groups.yaml"
defaults_file: "defaults.yaml"
runner:
plugin: threaded
options:
num_workers: 10
groups.yaml
Euro:
data:
region: Europe
USA:
data:
region: USA
hosts.yaml
R1:
hostname: 192.168.1.22
username: admin
password: admin
groups:
- Euro
R2:
hostname: 192.168.1.23
username: admin
password: admin
groups:
- Euro
R3:
hostname: 192.168.1.24
username: admin
password: admin
groups:
- USA
defaults.yaml
# (Optional default parameters, leave blank for now)
Step 2: Create the Runbook
Create a new Python file called runbook18.py inside the same folder.
runbook18.py
from nornir import InitNornir
from nornir_scrapli.tasks import send_command
from nornir_utils.plugins.functions import print_result
nr = InitNornir(config_file="config.yaml")
results = nr.run(
task=send_command,
command="show version"
)
print_result(results)
Step 3: Execute the Runbook
Open a terminal, navigate to the folder containing the runbook, and run:
python3 runbook18.py
You’ll see the show version output for R1, R2, and R3 displayed directly in your terminal.
Verification
You can verify the command manually on a device using console or SSH:
ssh admin@192.168.1.22
# Then run:
show version
The output should match what Nornir displayed in the terminal.
Conclusion
That’s it! You’ve created your first Nornir automation runbook. This setup forms the foundation for more complex automation tasks like configuration pushes, templated deployments, and data validation.
Stay tuned for the next video where we’ll dive into multi-command execution and configuration automation.
– Lenny DoesIT



Leave a comment