netbox-as-ansible-inventory
netbox-as-ansible-inventory copied to clipboard
Cannot group by status field
Hi,
I am having issues when I enable grouping on the status field. Custom fields are working fine, but when enabling this in the netbox.yml:
group_by:
# Default section in Netbox.
default:
- status
I get the following error:
[post_j@aw5034-mgt playbooks]$ ./netbox.py --list The key 'name' is not found. Please remember, Python is case sensitive.
Maybe I am overlooking something, does somebody has any idea?
Thanks!
I think I've found the issue: The status section has not a key named 'name', only label. So when you try to group by the status, it cannot find the key 'name' and it will create an error.
For me it is easy to fix as the status field is the only field I want to group_by in the default section:
self.key_map = { "default": "name", with self.key_map = { "default": "label",
However, if you want to group by one of the other default fields, that wont work anymore.
This PR implements more-or-less what you're asking about:
https://github.com/AAbouZaid/netbox-as-ansible-inventory/pull/23
It's perhaps not the most ideal solution since it requires the netbox.yml
author to know which keys have what name in the JSON returned by netbox, but does allow the use of all types at the same time.