Netbox Get Nornir Inventory Task¤
task api name:
get_nornir_inventory
Builds a Nornir inventory from NetBox device data. Nornir workers can call this task during startup to source hosts, host data, platform, hostname, interfaces, connections, circuits, and BGP peerings from NetBox.

How It Works¤
- Nornir worker or client submits a
get_nornir_inventoryrequest to the NetBox worker - NetBox worker checks the target NetBox instance status
- NetBox worker fetches device data with
get_devices - NetBox worker builds a Nornir
hostsinventory from NetBox device data and config context - Optional interface, connection, circuit, and BGP peering datasets are added to host data
- NetBox worker returns the assembled Nornir inventory
Inputs¤
| Parameter | Required | Description |
|---|---|---|
filters |
No | NetBox device filter dictionaries |
devices |
No | Device names to include in inventory |
instance |
No | NetBox instance name to target |
interfaces |
No | True to include interfaces, or a dictionary of get_interfaces kwargs |
connections |
No | True to include connections, or a dictionary of get_connections kwargs |
circuits |
No | True to include circuits, or a dictionary of get_circuits kwargs |
bgp_peerings |
No | True to include BGP peerings, or a dictionary of get_bgp_peerings kwargs |
nbdata |
No | Include NetBox device data in host data, default True |
primary_ip |
No | Primary IP family to use for hostname, default ip4 |
cache |
No | Cache usage mode passed to supporting data retrieval tasks |
Output¤
Returns a Nornir inventory dictionary:
{
"hosts": {
"ceos-leaf-1": {
"hostname": "192.0.2.11",
"platform": "eos",
"groups": ["lab"],
"data": {
"site": {"name": "lab"},
"interfaces": {},
"connections": {},
},
},
},
}
Notes / Gotchas¤
- The host name can be overridden by
config_context.nornir.nameon the NetBox device. - If host
platformorhostnameis not present in NetBox config context, the task derives them from NetBox platform and primary IP fields. interfaces,connections,circuits, andbgp_peeringscan beTrueor dictionaries with kwargs for the related task.- The current NFCLI command model does not expose
get_nornir_inventorydirectly undernetbox get, so this task is commonly used by Nornir worker startup or Python API callers.
Examples¤
from norfab.core.nfapi import NorFab
nf = NorFab(inventory="./inventory.yaml")
nf.start()
client = nf.make_client()
# build inventory for specific devices
result = client.run_job(
"netbox",
"get_nornir_inventory",
workers="any",
kwargs={
"devices": ["ceos-leaf-1", "ceos-leaf-2"],
},
)
# build inventory from NetBox filters
result = client.run_job(
"netbox",
"get_nornir_inventory",
workers="any",
kwargs={
"filters": [{"site": "lab", "status": "active"}],
},
)
# include related interface and connection data
result = client.run_job(
"netbox",
"get_nornir_inventory",
workers="any",
kwargs={
"devices": ["ceos-leaf-1"],
"interfaces": {"ip_addresses": True},
"connections": True,
"cache": "refresh",
},
)
# use IPv6 primary addresses for hostnames
result = client.run_job(
"netbox",
"get_nornir_inventory",
workers="any",
kwargs={
"devices": ["ceos-leaf-1"],
"primary_ip": "ip6",
},
)
nf.destroy()
Python API Reference¤
Retrieve and construct Nornir inventory from NetBox data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab Job object containing relevant metadata |
required |
filters
|
list
|
List of filters to apply when retrieving devices from NetBox. |
None
|
devices
|
list
|
List of specific devices to retrieve from NetBox. |
None
|
instance
|
str
|
NetBox instance to use. |
None
|
interfaces
|
Union[dict, bool]
|
If True, include interfaces data in the inventory. If a dict, use it as arguments for the get_interfaces method. |
False
|
connections
|
Union[dict, bool]
|
If True, include connections data in the inventory. If a dict, use it as arguments for the get_connections method. |
False
|
circuits
|
Union[dict, bool]
|
If True, include circuits data in the inventory. If a dict, use it as arguments for the get_circuits method. |
False
|
nbdata
|
bool
|
If True, include a copy of NetBox device's data in the host's data. |
True
|
primary_ip
|
str
|
Specify whether to use 'ip4' or 'ip6' for the primary IP address. Defaults to 'ip4'. |
'ip4'
|
cache
|
Union[bool, str]
|
Cache usage options:
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Result
|
Nornir inventory dictionary containing hosts and their respective data. |
Source code in norfab\workers\netbox_worker\nornir_inventory_tasks.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |