netbox-community / ansible_modules

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

[Bug]: Error when changing the subnet mask of an existing IP address (module netbox_ip_address) #1204

Open Cyrilpop opened 5 months ago

Cyrilpop commented 5 months ago

Ansible NetBox Collection version

v2.14.2

Ansible version

ansible [core 2.14.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/netbox/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /usr/share/ansible/ansible_collections
  executable location = /usr/bin/ansible
  python version = 3.11.2 (main, Feb 17 2023, 09:28:16) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True

NetBox version

v3.6.5

Python version

3.11

Steps to Reproduce

    - name: "[Create IPs]"
      netbox.netbox.netbox_ip_address:
        data:
          address: "12.34.56.78"
          assigned_object:
            device: test-device
            name: test-interface-1
          vrf: test-vrf-1

    - name: "Change subnet mask"
      netbox.netbox.netbox_ip_address:
        data:
          address: "12.34.56.78/27"
          assigned_object:
            device: test-device
            name: test-interface-1
          vrf: test-vrf-1

Expected Behavior

Possible bug in Ansible inventory regarding subnet mask. When changing the mask of an existing IP, the update should be reflected in Netbox without generating any errors.

Observed Behavior

When changing the subnet mask in the inventory, the following message is displayed, although the update should be performed without having to manually delete in Netbox.

msg: '{"address":["Duplicate IP address found in test-vrf-1: 12.34.56.78/32"]}'
lmas-chwy commented 1 month ago

Im having similar issue after I upgraded to netbox 3.7. The module is unable to detect if the ip already exsist to update it instead of trying to create a new ip.

I believe there was a new feature added to netbox where it checks if the ip exsist on a given VRF and it doesnt let you have duplicate ip on the same vrf.

My issue happens because I have a job that scans arp table on the devices and adds those IP to Netbox IPAM. Then when i try to add a device with an IP that already exsist in Netbox instead of trying to update that IP and attach it to the device it tries to create it and therefore gives this error.

"msg": "{\"address\":[\"Duplicate IP address found in global table: 10.0.2.62/32\"]}"}