NetAuto Academy

Advanced Lab

Multi-Device Automation Workflow

Advanced30 min

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)
Local/offline only, against NAPALM's real mock driver. No real device, controller, or credential is used or required -- requires nornir, napalm, and nornir_napalm installed locally (pip install nornir napalm nornir_napalm), exactly as in Nornir for Network Engineers and 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.

inventory/hosts.yaml
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-PROD2

Sample 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:

  1. Filters nr down to only hosts where data["environment"] == "staging".
  2. Runs napalm_get(getters=["get_facts", "get_interfaces"]) against that filtered subset only.
  3. Returns a dict keyed by hostname, each value containing: vendor (from get_facts), interface_count, and interfaces_up (how many interfaces have is_up: true).
Hints

Expected output

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.

Validation checklist

Self-check only -- nothing here is submitted or graded. Compare against your own output manually.

Solution

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

Done with this lesson?