Skip to content

[Bug]: Cannot assign existing IP to network interface #975

Open
@cfiehe

Description

@cfiehe

Ansible NetBox Collection version

v3.12.0

Ansible version

ansible [core 2.14.1]
  config file = /home/ansible/automation/projects/provisioning/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ansible/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/ansible/automation/projects/provisioning/collections
  executable location = /home/ansible/.local/bin/ansible
  python version = 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True

NetBox version

v3.4.7

Python version

3.10

Steps to Reproduce

If an IP address already exists in our Netbox, it cannot be assigned to an interface. The module always instructs the Netbox to create a new IP. This results in a Duplicate IP address exception, when Enforce unique space is enabled, or in a duplicate IP.

- name: Create an IP address
  netbox.netbox.netbox_ip_address:
    netbox_url: "{{ netbox_url }}"
    netbox_token: "{{ netbox_token }}"
    data:
      address: 10.1.60.232/24
      tenant: my_company
      vrf: my_company-RFC1918
      status: Active
    state: present

- name: Assign IP address to existing interface
  netbox.netbox.netbox_ip_address:
    netbox_url: "{{ netbox_url }}"
    netbox_token: "{{ netbox_token }}"
    data:
      address: 10.1.60.232/24
      assigned_object:
        virtual_machine: any_vm.local
        name: ens224
      tenant: my_company
      vrf: my_company-RFC1918
      status: Active
    state: present

Expected Behavior

The existing IP should be modified and should be attached to the specified interface.

Observed Behavior

The VRF my_company-RFC1918 uses the option Enforce unique space , that is why the assignment fails with a Duplicate IP address, because the module tries to create a new IP instead of modifying the existing one:

fatal: [any_vm.local -> localhost]: FAILED! => {"changed": false, "msg": "{\"address\":[\"Duplicate IP address found in VRF my_company-RFC1918: 10.1.60.232/24\"]}"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions