-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hostname Attribute error when NetBoxInventory2 plugin in use #779
Comments
What does the following show? for host_obj in nr.inventory.hosts:
print(host_obj.hostname) Are there any devices that do not have a hostname? |
while
In this particular case there's only 1 device in inventory |
May the root of the problem be in object type?
|
My error above...so what do you get with this: for name, host_obj in nr.inventory.hosts.items():
print(f"{name} -> {host_obj.hostname}") |
You might need to look at the Python debugger and see what things are at this line 467:
i.e. print out both |
Below is pycharm screenshot with |
Fore reference, here is the type definition: https://github.com/nornir-automation/nornir/blob/develop/nornir/core/inventory.py#L216 and where sp is coming from: https://github.com/nornir-automation/nornir/blob/develop/nornir/core/inventory.py#L465 However, according to your traceback and debug information This is most likely a plugin issue so I'd suggest checking with them. |
Fyi, Faced same issue. thanks |
@dbarrosop The problem is here https://github.com/wvandeun/nornir_netbox/blob/860d2f80e3fd2b2989c33044c560decdd2685cf1/nornir_netbox/plugins/inventory/netbox.py#L47 We try to retrieve the These functions were directly copied from Nornir's Simple inventory plugin, so the same issue should also exist in that plugin: nornir/nornir/plugins/inventory/simple.py Line 44 in 33076fa
The nornir_ansible inventory plugin seems to have the exact same approach as well btw:https://github.com/carlmontanari/nornir_ansible/blob/d00fa4788bbca5b24a18b9c15ccc6361bd890bd0/nornir_ansible/plugins/inventory/ansible.py#L471 (probably also copied from simple inventory) If I modify the line to: connection_options=_get_connection_options(data.get("data", {}).get("connection_options", {})), then it seems to work properly >>> nr.inventory.defaults.connection_options
{'netmiko': <nornir.core.inventory.ConnectionOptions object at 0x107e4aa90>}
>>> nr.inventory.defaults.connection_options.get("netmiko").hostname
"10.10.10.10" |
This doesn't look correct though. This would mean that your defaults_dict looks like:
And it shouldn't as connection_options is an attribute of If I am wrong, I'd suggest you create a branch with a unit test that triggers the issue and I will try to help out but I am confident this is not a nornir issue as we are actively testing this scenario. |
Appreciate your help @ktbyers @dbarrosop |
Similar issue was described here - #279
In my case primary_ip is defined in Netbox and populates 'hostname' attribute
nr.run(netmiko_send_config, config_commands=commands)
gets back errorThe text was updated successfully, but these errors were encountered: