load_yaml

Loads a YAML file.

Example

[20]:
from nornir import InitNornir
from nornir_utils.plugins.tasks.data import load_yaml

nr = InitNornir(
    inventory={
        "plugin": "SimpleInventory",
        "options": {"host_file": "data/hosts.yaml", "group_file": "data/groups.yaml"},
    }
)

r = nr.run(task=load_yaml, file="data/ip_addresses.yaml")
for host, m_result in r.items():
    print()
    print("-" * 40)
    print(f"Host: {host}")
    print(f"YAML data: {m_result.result}")
    print("-" * 40)

----------------------------------------
Host: dev1.group_1
YAML data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']
----------------------------------------

----------------------------------------
Host: dev2.group_1
YAML data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']
----------------------------------------

----------------------------------------
Host: dev3.group_2
YAML data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']
----------------------------------------

----------------------------------------
Host: dev4.group_2
YAML data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']
----------------------------------------

----------------------------------------
Host: dev5.no_group
YAML data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']
----------------------------------------