-
Notifications
You must be signed in to change notification settings - Fork 262
Description
Ansible NetBox Collection version
v3.22.0
Ansible version
ansible [core 2.16.14]
config file = /root/netbox_ansible_modules/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.12/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /bin/ansible
python version = 3.12.12 (main, Nov 14 2025, 00:00:00) [GCC 11.5.0 20240719 (Red Hat 11.5.0-11)] (/usr/bin/python3.12)
jinja version = 3.1.6
libyaml = False
NetBox version
v4.5.0
Python version
3.11
Steps to Reproduce
NOTE: This is copied almost verbatim from #1413 because it's exactly the same save that it affects vm interfaces opposed to device interfaces. I'm creating this issue to justify a PR to fix it.
Create two virtual interfaces. Create and assign two separate, identical MAC address on both virtual interfaces. Assign the MAC address as primary on both virtual interfaces (fails). This should be possible as they are actually two separate mac_address objects, each assigned to a different vm interface:
- name: Create MAC addresses
delegate_to: localhost
netbox.netbox.netbox_mac_address:
netbox_url: "{{ netbox_url }}"
netbox_token: "{{ netbox_token }}"
data:
assigned_object:
virtual_machine: test_vm
name: "{{ item }}"
mac_address: AA:BB:CC:DD:EE:FF
query_params:
- assigned_object
- name
loop:
- Gig-E1
- virtual1
register: netbox_mac_address_result
- name: Set NIC's Primary MAC addresses
delegate_to: localhost
netbox.netbox.netbox_vm_interface:
netbox_url: "{{ netbox_url }}"
netbox_token: "{{ netbox_token }}"
data:
virtual_machine: test_vm
name: "{{ item.item }}"
primary_mac_address: AA:BB:CC:DD:EE:FF
loop: "{{ netbox_mac_address_result.results }}"
Expected Behavior
MAC address object assigned to interface Gig-E1 on test_vm is set as primary_mac_address on interface Gig-E1. MAC address object assigned to interface virtual1 on test_vm is set as primary_mac_address on interface virtual1.
Observed Behavior
Attempt to assign MAC address as primary mac adress of an interface results in the error:
msg: More than one result returned for primary_mac_address
Despite the fact that there is only one unique mac address defined on each interface. It only happens to be the same mac_address string for each of those interfaces.
I have tried passing the mac address object id as primary_mac_address:
- name: Set NIC's Primary MAC addresses
delegate_to: localhost
netbox.netbox.netbox_vm_interface:
netbox_url: "{{ netbox_url }}"
netbox_token: "{{ netbox_token }}"
data:
virtual_machine: test_vm
name: "{{ item.item }}"
primary_mac_address:
id: "{{ item.mac_address.id "}}
loop: "{{ netbox_mac_address_result.results }}"
But this results in the error:
msg: 'Could not resolve id of primary_mac_address: {''id'': ''1147''}'
Passing the full mac_address object as primary_mac_address yields the same error.
It seems that the primary_mac_address parameter only accepts an actual MAC address string but then searches for it without considering the assigned_object being the same as the device_interface where we try to set the primary_mac_address for.