nornir-automation / nornir

Pluggable multi-threaded framework with inventory management to help operate collections of devices
https://nornir.readthedocs.io/
Apache License 2.0
1.4k stars 237 forks source link

issue reading Ansible inventory #460

Closed lutfisan closed 4 years ago

lutfisan commented 4 years ago
import nornir
from nornir import InitNornir

nr = InitNornir(
        core={"num_workers": 20},
        inventory={
            "plugin": "nornir.plugins.inventory.ansible.AnsibleInventory",
            "options": {
                "host_file": "inventory/hosts"
            }
        }
    )

print(nr.inventory.groups)
print(nr.inventory.hosts)

image

my inventory/hosts:

[router:children]
iosxe
iosxr
juniper

[router:vars]
ansible_user=user
ansible_password=pass
ansible_connection=network_cli

[iosxe:vars]
ansible_network_os=ios

[iosxr:vars]
ansible_network_os=iosxr

[juniper:vars]
ansible_network_os=junos
ansible_connection=netconf

[iosxe]
192.168.32.1
192.168.32.104
192.168.32.105

[iosxr]
192.168.246.229
192.168.247.139
192.168.247.77

[juniper]
192.168.0.1
192.168.0.10
192.168.0.11
carlmontanari commented 4 years ago

You’re looking for “hostsfile” in the config, not “host_file”

lutfisan commented 4 years ago

You’re looking for “hostsfile” in the config, not “host_file”

I change host_file to hostsfile but still not work

carlmontanari commented 4 years ago

nr = InitNornir(
        core={"num_workers": 20},
        inventory={
            "plugin": "nornir.plugins.inventory.ansible.AnsibleInventory",
            "options": {
                "hostsfile": "tmp"
            }
        }
    )

print(nr.inventory.groups)
print(nr.inventory.hosts)

copy/pasted your inventory to that tmp file above and works as expected w/ nornir 2.3.0:


{'192.168.32.1': Host: 192.168.32.1, '192.168.32.104': Host: 192.168.32.104, '192.168.32.105': Host: 192.168.32.105, '192.168.246.229': Host: 192.168.246.229, '192.168.247.139': Host: 192.168.247.139, '192.168.247.77': Host: 192.168.247.77, '192.168.0.1': Host: 192.168.0.1, '192.168.0.10': Host: 192.168.0.10, '192.168.0.11': Host: 192.168.0.11}```
dbarrosop commented 4 years ago

I am closing this issue as this is not an issue related to nornir. For support I'd suggest you to head to https://nornir.discourse.group