load_json
Loads a JSON file.
Example
[6]:
from nornir import InitNornir
from nornir_utils.plugins.tasks.data import load_json
nr = InitNornir(
inventory={
"plugin": "SimpleInventory",
"options": {"host_file": "data/hosts.yaml", "group_file": "data/groups.yaml"},
}
)
r = nr.run(task=load_json, file="data/ip_addresses.json")
for host, m_result in r.items():
print()
print("-" * 40)
print(f"Host: {host}")
print(f"JSON data: {m_result.result}")
print("-" * 40)
----------------------------------------
Host: dev1.group_1
JSON data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']
----------------------------------------
----------------------------------------
Host: dev2.group_1
JSON data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']
----------------------------------------
----------------------------------------
Host: dev3.group_2
JSON data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']
----------------------------------------
----------------------------------------
Host: dev4.group_2
JSON data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']
----------------------------------------
----------------------------------------
Host: dev5.no_group
JSON data: ['8.8.8.8', '8.8.4.4', '1.1.1.1', '1.0.0.1']
----------------------------------------