# Trying to build a dynamic query using netbox.nb\_lookup

**URL:** <https://forum.ansible.com/t/trying-to-build-a-dynamic-query-using-netbox-nb-lookup/36108>\
**Category:** Ansible Project\
**Created:** [December 14, 2021, 8:50am UTC](https://forum.ansible.com/t/trying-to-build-a-dynamic-query-using-netbox-nb-lookup/36108 "2021-12-14T08:50:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwispy](https://avatars.discourse-cdn.com/v4/letter/c/b782af/32.png) [@cwispy](https://forum.ansible.com/u/cwispy)\
**Post date:** [December 14, 2021, 8:50am UTC](https://forum.ansible.com/t/trying-to-build-a-dynamic-query-using-netbox-nb-lookup/36108/1 "2021-12-14T08:50:38Z")

</div>

Hi Everyone,

I am building some automation for our Netbox as the source of truth and using webhooks to fire off tasks for things like interface updates and vlan creation / deletions.

The issue I have is that I am trying to pass the device id as a variable to the query for the netbox.nb\_lookup collection and it is not working.

I have tried many different ways of building the query, and they all fail in different ways. At least this one returns valid query text in the debug output, but does not run the query.

tasks:

- name: “Get platform from Netbox”

set\_fact:  
platformos: query({{qryfilter}})  
vars:  
qryfilter: “‘netbox.netbox.nb\_lookup’, ‘devices’, api\_filter=‘id={{mydeviceid}}’, api\_endpoint={{netbox\_url}}, token={{netbox\_token}}”

string(80) “TASK [Get platform from Netbox] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*”  
[36]=\>  
string(45) “task path: /home/ansible/get\_interface.yml:13”  
[37]=\>  
string(27) “ok: [HP-2530-48G-Demo] =\> {”  
[38]=\>  
string(22) " “ansible\_facts”: {"  
[39]=\>  
string(178) " “platformos”: “query(‘netbox.netbox.nb\_lookup’, ‘devices’, api\_filter=‘id=15’, api\_endpoint=https://, token=)”"  
[40]=\>  
string(6) " },"  
[41]=\>  
string(20) " “changed”: false"

Any pointers would be greatly appreciated.
