netbox-community / ansible_modules

NetBox modules for Ansible using Ansible Collections
GNU General Public License v3.0
333 stars 216 forks source link

[Bug]: Adding an interface to an existing bridge fails #1068

Open BackblazeJeremy opened 1 year ago

BackblazeJeremy commented 1 year ago

Ansible NetBox Collection version

v3.14.0

Ansible version

ansible [core 2.15.1]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/jmccoy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/jmccoy/.local/lib/python3.11/site-packages/ansible
  ansible collection location = /home/jmccoy/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/jmccoy/.local/bin/ansible
  python version = 3.11.4 (main, Jun  7 2023, 00:00:00) [GCC 13.1.1 20230511 (Red Hat 13.1.1-2)] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True

NetBox version

3.5.9

Python version

3.11

Steps to Reproduce

This can be reproduced by running the following example playbook: test.yml.txt

The playbook creates a minimal device, creates a bridge interface, and attempts to create another interface that will belong to the bridge.

Expected Behavior

With the provided information, I would expect that the last interface would be created and associated with the bridge. The provided information includes the device name and bridge interface name it should be associated with, which in this case there is only one possible result that can come from that combination.

Observed Behavior

The task fails with the message: More than one result returned for bridge, which is bogus.

Here is the full output of by example run with -vvv: test.out.txt

Here is a screenshot showing the device it created, which only has one possible result for a bridge with that name: Screenshot_20230912_160646

Due to this error, our automation is incapable of associating underlying interfaces with bridges. Performing this association manually via the web UI works as expected.

leijonatm commented 1 year ago

+1 I am experiencing the same having ansible version 2.14.6, netbox version 3.6.3, python 3.11.5 and ansible collection version 3.13.0

Correction I thought was running collection 3.13 but my system thinks other wise

% ansible-galaxy collection install --upgrade netbox.netbox Starting galaxy collection install process Process install dependency map Starting collection install process 'netbox.netbox:3.14.0' is already installed, skipping.

gustojoel commented 1 year ago

+1 I am also seeing this issue, but I would expand the impact a bit. I am getting an error message indicating that multiple bridges are found that match the name. This is true in my environment, there are multiple devices that have a "vlan.75" interface, but not on this device. If I complete this configuration via the web UI, it works just fine - but programmatically I experience this above bug.

Ansible: 2.15.5 Python: 3.10.13 NetBox: 3.3.5 Ansible Galaxy Collection (netbox.netbox): 3.15.0

image

I will be subscribing to this issue, as I hope to be notified when there is something new available to try.

BackblazeJeremy commented 4 months ago

As a workaround: if you know the ID of the bridge you're trying to associate, you can pass it as a dict like so:

- netbox.netbox.netbox_device_interface:
    data:
      device: "{{ netbox_device_name }}"
      name: "{{ netbox_interface_name }}"
      bridge:
        id: "{{ netbox_bridge_id }}"

This general pattern seems to work for other data fields as well. Not everyone can readily access those IDs, so I believe this bug should remain open, but this pattern may be helpful to others.