NETBOX - Get interface of virtual_machine

Hi,

From Netbox module for Ansible, i tried to get interface of a VM.

With this i got all the interface in Netbox :

- debug:
     msg: "{{ query('netbox.netbox.nb_lookup', 'virtualization-interfaces', api_endpoint=netbox.url, token=netbox.token) }}"

But now i want to filter on a specific virtual_machine name and i try like below :

-  set_fact:
    tmp_netbox_api_filter: "virtual_machine_name=XXXXXX"
- debug:
     msg: "{{ query('netbox.netbox.nb_lookup', 'virtualization-interfaces', api_filter=tmp_netbox_api_filter, api_endpoint=netbox.url, token=netbox.token) }}"

The [virtual_machine_name] that i search exist but for the moment with the filter above i got all the Netbox Interface.

Do you know with lookup plugin for virtualization-interfaces how can i get interface of a VM please ?

Thanks for your help,

Matt

Hi all,

I have an error in the api_filter.

In the documentation, [ netbox.netbox.nb_lookup lookup – Queries and returns elements from NetBox — Ansible Community Documentation ]
→ “The api_filter to use. Filters should be key value pairs separated by a space.”

virtual_machine_name is not a KEY ! :slight_smile:

But virtual_machine_id is a key so i fix my filter like below and now it works.


- set_fact:
    tmp_netbox_api_filter: "virtual_machine_id=XXX"

Matt