netbox-community / netbox-community/ansible_modules
[Bug]: multiple results returned for untagged_vlan when vlan & vlan_group for interface is defined
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 399
- Forks
- 279
- PR merge metrics
- No merged PRs in 30d
Description
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 vlan_groups
netbox:
site_group:
- name: hq
site:
- name: main
associated to site_group 'hq'
vlan_group:
- name: access-vlan
associated to scope site_group 'hq'
vlan:
- name: VLAN100
- name: VLAN200
both vlans in vlan_group 'access-vlan'
device:
- name switch1
associated to site 'main' - interface GigabitEthernet1/0/1
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"
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in plugins/module_utils/netbox_utils.py around _nb_endpoint_get, then inspect the netbox_device_interface module and pynetbox endpoint get behavior shown in the traceback. Reproduce the VLAN setup and verify that an interface with the supplied name and vlan_group resolves to one untagged VLAN without the multiple-results error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ansible, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100