netbox-community / ansible_modules

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

[Bug]: multiple results returned for untagged_vlan when vlan & vlan_group for interface is defined #1237

Open sebastianreifetshammer opened 1 month ago

sebastianreifetshammer commented 1 month ago

Ansible NetBox Collection version

v3.18.0

Ansible version

ansible [core 2.15.4]
  config file = /opt/ansible/ansible-playbooks/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/ansible/ansible-venv/lib/python3.10/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/ansible/ansible-venv/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/opt/ansible/ansible-venv/bin/python3)
  jinja version = 3.1.2
  libyaml = True

NetBox version

v.4.0.2

Python version

3.10

Steps to Reproduce

_this is a setup to reproduce this issue, in my prod. i have multiple vlans with the same vlan-id & name but in different vlangroups

netbox:

site_group:

site:

vlan_group:

vlan:

device:

ansible

- name: Add access interface to NetBox
    netbox.netbox.netbox_device_interface:
      netbox_url: "{{ netbox_url }}"
      netbox_token: "{{ netbox_api_key }}"
      data:
        device: switch1
        name: interface GigabitEthernet1/0/1
        mode: access
        untagged_vlan:
          - name: VLAN100
          - vlan_group: access-vlan

Expected Behavior

Expected to update interface GigabitEthernet1/0/1 mode access, untagged_vlan to VLAN100 from vlan_group access-vlan

Observed Behavior

The full traceback is:
  File "/tmp/ansible_netbox.netbox.netbox_device_interface_payload_vhpyarj5/ansible_netbox.netbox.netbox_device_interface_payload.zip/ansible_collections/netbox/netbox/plugins/module_utils/netbox_utils.py", line 795, in _nb_endpoint_get
    response = nb_endpoint.get(**query_params)
  File "/opt/ansible/ansible-venv/lib/python3.10/site-packages/pynetbox/core/endpoint.py", line 166, in get
    raise ValueError(
fatal: [switch1]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "cert": null,
            "data": {
                "bridge": null,
                "custom_fields": null,
                "description": null,
                "device": "switch1",
                "duplex": null,
                "enabled": null,
                "form_factor": null,
                "label": null,
                "lag": null,
                "mac_address": null,
                "mark_connected": null,
                "mgmt_only": null,
                "mode": "access",
                "mtu": null,
                "name": "interface GigabitEthernet1/0/1",
                "parent_interface": null,
                "poe_mode": null,
                "poe_type": null,
                "speed": null,
                "tagged_vlans": null,
                "tags": null,
                "tx_power": null,
                "type": null,
                "untagged_vlan": [
                    {
                        "name": "VLAN100"
                    },
                    {
                        "vlan_group": "access-vlan"
                    }
                ],
                "vrf": null,
                "wwn": null
            },
            "netbox_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "netbox_url": "http://127.0.0.1:8000",
            "query_params": null,
            "state": "present",
            "update_vc_child": false,
            "validate_certs": true
        }
    },
    "msg": "More than one result returned for untagged_vlan"
}