Advanced Lab
Multi-Device Automation Workflow
Objective
Combine Nornir's inventory filtering with NAPALM's normalized getters into one multi-step workflow that only ever touches the intended subset of a mixed-vendor fleet.
Builds on Multi-vendor Automation.
Prerequisites
- Comfortable with InitNornir(), nr.run(), and nr.filter() (Nornir for Network Engineers)
- Comfortable with napalm_get() and driver resolution from inventory (Multi-vendor Automation)
Scenario
The problem
A fleet spans two environments -- staging and production -- and two vendors. You need a facts-and-interface-state report for the staging devices only, without writing separate code per vendor and without any risk of the report-generation step touching production. Nornir for Network Engineers taught filtering; Multi-vendor Automation taught vendor-neutral getters. This lab is the first place this specific combination -- filter by a custom environment field, then collect normalized state only from what matched -- gets built end to end.
Starter data
Four devices, two environments, two vendors -- a fresh inventory, not reused from any lesson's own fleet.
EDGE-STG1:
hostname: 127.0.0.1
platform: mock
data:
environment: staging
vendor: cisco_ios
connection_options:
napalm:
extras:
optional_args:
path: fixtures/EDGE-STG1
EDGE-STG2:
hostname: 127.0.0.1
platform: mock
data:
environment: staging
vendor: arista_eos
connection_options:
napalm:
extras:
optional_args:
path: fixtures/EDGE-STG2
CORE-PROD1:
hostname: 127.0.0.1
platform: mock
data:
environment: production
vendor: cisco_ios
connection_options:
napalm:
extras:
optional_args:
path: fixtures/CORE-PROD1
CORE-PROD2:
hostname: 127.0.0.1
platform: mock
data:
environment: production
vendor: arista_eos
connection_options:
napalm:
extras:
optional_args:
path: fixtures/CORE-PROD2Sample inventory written for this lab -- platform: mock everywhere (NAPALM's real mock driver, per Multi-vendor Automation), with data.vendor labeling the identity each host is "designed to resemble," not a live driver. 127.0.0.1 and platform: mock are the same offline-testing convention used throughout this curriculum.
Deliberately incomplete fixtures
Only fixtures/EDGE-STG1/ and fixtures/EDGE-STG2/ need to exist for this lab's required task. No fixture files exist for CORE-PROD1/CORE-PROD2 — if your solution's filtering is wrong and it tries to collect from them, NAPALM's mock driver will raise a real NotImplementedError rather than silently succeeding. Use that as a genuine check on your own filter, not just a warning to read past.
Task
Write load_fleet() that builds a Nornir inventory from inventory/hosts.yaml (SimpleInventory, matching every prior use of this plugin).
Write build_staging_report(nr) that:
- Filters
nrdown to only hosts wheredata["environment"] == "staging". - Runs
napalm_get(getters=["get_facts", "get_interfaces"])against that filtered subset only. - Returns a dict keyed by hostname, each value containing:
vendor(fromget_facts),interface_count, andinterfaces_up(how many interfaces haveis_up: true).
Expected output
Full fleet: ['EDGE-STG1', 'EDGE-STG2', 'CORE-PROD1', 'CORE-PROD2']
Staging subset: ['EDGE-STG1', 'EDGE-STG2']
--- Staging facts report ---
EDGE-STG1: {'vendor': 'Cisco', 'interface_count': 2, 'interfaces_up': 1}
EDGE-STG2: {'vendor': 'Arista', 'interface_count': 3, 'interfaces_up': 2}Real, verified output. CORE-PROD1 and CORE-PROD2 never appear in the staging report -- and since they have no fixture files at all, that absence is proof they were never touched, not just an assumption.
Self-check only -- nothing here is submitted or graded. Compare against your own output manually.
Solution
Try the task yourself first -- the full solution and explanation stay hidden until you click above.
Key takeaways
- nr.filter(environment="staging") reuses Nornir's own custom-data filtering exactly as taught -- no new mechanic, just a new field.
- Real, verified run: the staging subset (2 hosts, 2 vendors) was collected correctly; production hosts never appeared in the report.
- Deliberately missing fixtures for the production hosts turned "never touched" from an assumption into something a mistake would fail loudly on.
- NAPALM's real mock driver only -- no real device, controller, or credential was used or required.
Related lessons
Filtering the Inventory: F() and nr.filter()
The exact filtering mechanic this lab applies to a brand-new custom inventory field.
Read lessonDriver Selection from Inventory: platform and nornir_napalm's Connection Plugin
How each host's platform field resolves to the driver napalm_get() actually uses.
Read lessonDone with this lesson?