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 ---
 2 core:
 3     num_workers: 100
 4 
 5 inventory:
 6     plugin: nornir.plugins.inventory.simple.SimpleInventory
 7     options:
 8         host_file: "inventory/hosts.yaml"
 9         group_file: "inventory/groups.yaml"
10         defaults_file: "inventory/defaults.yaml"

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(
    core={"num_workers": 100},
    inventory={
        "plugin": "nornir.plugins.inventory.simple.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(core={"num_workers": 50}, config_file="config.yaml")
[6]:
nr.config.core.num_workers
[6]:
50