Replies: 1 comment 3 replies
-
Change your api_filter to look for the slug. So... "{{ query('netbox.netbox.nb_lookup', 'devices', api_endpoint='http://<netbox_IP>:8000', token='my_token', api_filter='role=power-distributor') }}" |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all!
Ansible version: 2.17
Netbox version 4.1.4
i trying use nb_lookup for find free outlets on Power distributor. Initially i want find devices with power distributor role in the rack, but get error not found:
An unhandled exception occurred while running the lookup plugin 'netbox.netbox.nb_lookup'. Error was a <class 'pynetbox.core.query.RequestError'>, original message: The request failed with code 400 Bad Request: {'role': ['Select a valid choice. Power distributor is not one of the available choices.']}. The request failed with code 400 Bad Request: {'role': ['Select a valid choice. Power distributor is not one of the available choices.']}
Task example:
- name: Obtain list of devices from NetBox debug: msg: > {{item}} loop: "{{ query('netbox.netbox.nb_lookup', 'devices', api_endpoint='http://<netbox_IP>:8000', token='my_token', api_filter='role=\"Power distributor\"') }}"
next i try for get all roles:
and receive all roles including "Power distributor"
Task:
- name: Obtain list of all roles from NetBox debug: msg: > {{item}} loop: "{{ query('netbox.netbox.nb_lookup', 'device-roles', api_endpoint='http://<netbox_IP>:8000', token='my_token') }}"
RESULT:
`MSG:
{'key': 5, 'value': {'id': 5, 'url': 'http://<netbox_IP>:8000/api/dcim/device-roles/5/', 'display_url': 'http://<netbox_IP>:8000/dcim/device-roles/5/', 'display': 'Power distributor', 'name': 'Power distributor', 'slug': 'power-distributor', 'color': 'ff5722', 'vm_role': False, 'config_template': None, 'description': '', 'tags': [], 'custom_fields': {}, 'created': '2022-06-16T19:34:11.923602Z', 'last_updated': '2024-10-18T22:06:13.076080Z', 'device_count': 12, 'virtualmachine_count': 0}}
ok: [shv01] => (item={'key': 11, 'value': {'id': 11, 'url': 'http://<netbox_IP>:8000/api/dcim/device-roles/11/', 'display_url': 'http://<netbox_ip>:8000/dcim/device-roles/11/', 'display': 'RDP Terminal Server', 'name': 'RDP Terminal Server', 'slug': 'rdp-terminal-server', 'color': '795548', 'vm_role': True, 'config_template': None, 'description': '', 'tags': [], '`
what wrong?
Beta Was this translation helpful? Give feedback.
All reactions