Initializing Nornir
Easiest way of initializing nornir is with the function InitNornir.
With InitNornir
you can initialize nornir with a configuration file, with code or with a combination of both.
Let’s start with a configuration file:
[2]:
%highlight_file config.yaml
[2]:
1---
2inventory:
3 plugin: SimpleInventory
4 options:
5 host_file: "inventory/hosts.yaml"
6 group_file: "inventory/groups.yaml"
7 defaults_file: "inventory/defaults.yaml"
8runner:
9 plugin: threaded
10 options:
11 num_workers: 100
Now to create the nornir object:
[3]:
from nornir import InitNornir
nr = InitNornir(config_file="config.yaml")
You can also initialize nornir programmatically without a configuration file:
[4]:
from nornir import InitNornir
nr = InitNornir(
runner={
"plugin": "threaded",
"options": {
"num_workers": 100,
},
},
inventory={
"plugin": "SimpleInventory",
"options": {
"host_file": "inventory/hosts.yaml",
"group_file": "inventory/groups.yaml"
},
},
)
Or with a combination of both methods:
[5]:
from nornir import InitNornir
nr = InitNornir(
config_file="config.yaml",
runner={
"plugin": "threaded",
"options": {
"num_workers": 50,
},
},
)
[6]:
nr.config.runner.options["num_workers"]
[6]:
50