Issues linking parent interface with netbox_device_interface module

Hello,

I’m attempting to use the netbox.netbox.netbox_device_interface module to create an interface and assign a parent interface to it. Here are the tasks I’m using to get the ID from the API:

        - name: Get bond0 Interface
          local_action:
            module: ansible.builtin.set_fact
            interface: "{{ query('netbox.netbox.nb_lookup', 'interfaces', api_filter='name=LAG0 device=' ~ device_name) }}"

        - name: List bond0 Interface values
          ansible.builtin.debug:
            msg: "{{ interface }}"

        - name: Get bond0 Interface ID
          ansible.builtin.set_fact:
            interfaceid: "{{ interface.0.value.id }}"

I then set the parent interface here:

    # VLAN 407 Interface/address block
    - name: Write 407 interface and address
      block:
        - name: Write 407 VLAN interface
          local_action:
            module: netbox.netbox.netbox_device_interface
            netbox_url: "{{ lookup('env', 'NETBOX_API') }}"
            netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') }}"
            data:
              name: "LAG0_VLAN407"
              label: "bond0.407"
              device: "{{ ansible_facts['hostname'] }}"
              enabled: "true"
              type: "Virtual"
              parent_interface: "{{ interfaceid }}"

When I attempt to run the playbook, I get the error ‘Could not resolve id of parent interface: ’. At this point I’m not sure what other value I need to provide, as I know the ID is correct when checked against the API for the parent interface and the documentation isn’t clear. Any help that can be provided is much appreciated.

Ultimately was able to fix this by setting jinja2_native = true in the ansible.cfg file. Note that this will cause some weirdness with other data types, especially null/None/undefined vars.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.