Skip to content

[Bug]: Unable to assign primary mac address when identical mac address exists #1413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
RobinR1 opened this issue May 8, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@RobinR1
Copy link

RobinR1 commented May 8, 2025

Ansible NetBox Collection version

v3.21.0

Ansible version

core version: 2.16.14

NetBox version

v4.2.6

Python version

3.11

Steps to Reproduce

Create a host with a physical and a virtual interface
Create the same MAC address on both virtual interfaces:
Assign the MAC address as primary on both virtual interfaces. This should be possible as it are actually 2 separate mac_address objects, each assigned to a different interface:

- name: Create MAC addresses
  delegate_to: localhost
  netbox.netbox.netbox_mac_address:
    netbox_url: "{{ netbox_url }}"
    netbox_token: "{{ netbox_token }}"
    data: 
      assigned_object:
        device: Test host
        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_device_interface:
    netbox_url: "{{ netbox_url }}"
    netbox_token: "{{ netbox_token }}"
    data:
      device: Test host
      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 host Test host is set as primary_mac_address on interface Gig-E1
MAC address object assigned to interface virtual1 on host Test host 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 eacht 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_device_interface:
    netbox_url: "{{ netbox_url }}"
    netbox_token: "{{ netbox_token }}"
    data:
      device: Test host
      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.

@RobinR1 RobinR1 added the bug Something isn't working label May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant