Trying to build a dynamic query using netbox.nb_lookup

417 views
Skip to first unread message

cwispy

unread,
Dec 14, 2021, 3:50:39 AM12/14/21
to Ansible Project
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://<redacted>, token=<redacted>)""
  [40]=>
  string(6) "    },"
  [41]=>
  string(20) "    "changed": false"

Any pointers would be greatly appreciated.
Reply all
Reply to author
Forward
0 new messages