diff --git a/changelogs/fragments/1323-fixing-bug-#975.yml b/changelogs/fragments/1323-fixing-bug-#975.yml new file mode 100644 index 00000000..c0ac8b42 --- /dev/null +++ b/changelogs/fragments/1323-fixing-bug-#975.yml @@ -0,0 +1,2 @@ +bugfixes: + - netbox_ip_address - Fixed the problem preventing assignment of an IP address to a network interface diff --git a/plugins/module_utils/netbox_ipam.py b/plugins/module_utils/netbox_ipam.py index f8a0131d..8d1b731f 100644 --- a/plugins/module_utils/netbox_ipam.py +++ b/plugins/module_utils/netbox_ipam.py @@ -205,6 +205,11 @@ def run(self): else: name = data.get("name") + if self.endpoint == "ip_addresses": + if "interface" in data: + data["assigned_object_id"] = data["interface"] + data["assigned_object_type"] = "dcim.interface" + if self.endpoint in SLUG_REQUIRED: if not data.get("slug"): data["slug"] = self._to_slug(name) diff --git a/tests/integration/targets/v3.5/tasks/netbox_ip_address.yml b/tests/integration/targets/v3.5/tasks/netbox_ip_address.yml index ce2b125a..c73fb9df 100644 --- a/tests/integration/targets/v3.5/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v3.5/tasks/netbox_ip_address.yml @@ -348,3 +348,52 @@ - test_sixteen['diff']['after']['state'] == "present" - test_sixteen['msg'] == "ip_address 10.120.10.1/32 created" - test_sixteen['ip_address']['address'] == "10.120.10.1/32" + +- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + address: 10.10.200.31/16 + interface: + device: test100 + name: GigabitEthernet2 + register: test_seventeen + +- name: 17 - ASSERT + ansible.builtin.assert: + that: + - test_seventeen is changed + - test_seventeen['diff']['before']['state'] == "absent" + - test_seventeen['diff']['after']['state'] == "present" + - test_seventeen['msg'] == "ip_address 10.10.200.31/16 created" + - test_seventeen['ip_address']['address'] == "10.10.200.31/16" + - test_seventeen['ip_address']['family'] == 4 + - test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_seventeen['ip_address']['assigned_object_id'] == 4 + +- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + prefix: 10.10.0.0/16 + interface: + name: GigabitEthernet2 + device: test100 + state: new + register: test_eighteen + +- name: 18 - ASSERT + ansible.builtin.assert: + that: + - test_eighteen is changed + - test_eighteen['diff']['before']['state'] == "absent" + - test_eighteen['diff']['after']['state'] == "present" + - test_eighteen['msg'] == "ip_address 10.10.0.2/16 created" + - test_eighteen['ip_address']['address'] == "10.10.0.2/16" + - test_eighteen['ip_address']['family'] == 4 + - test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_eighteen['ip_address']['assigned_object_id'] == 4 diff --git a/tests/integration/targets/v3.6/tasks/netbox_ip_address.yml b/tests/integration/targets/v3.6/tasks/netbox_ip_address.yml index ce2b125a..c73fb9df 100644 --- a/tests/integration/targets/v3.6/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v3.6/tasks/netbox_ip_address.yml @@ -348,3 +348,52 @@ - test_sixteen['diff']['after']['state'] == "present" - test_sixteen['msg'] == "ip_address 10.120.10.1/32 created" - test_sixteen['ip_address']['address'] == "10.120.10.1/32" + +- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + address: 10.10.200.31/16 + interface: + device: test100 + name: GigabitEthernet2 + register: test_seventeen + +- name: 17 - ASSERT + ansible.builtin.assert: + that: + - test_seventeen is changed + - test_seventeen['diff']['before']['state'] == "absent" + - test_seventeen['diff']['after']['state'] == "present" + - test_seventeen['msg'] == "ip_address 10.10.200.31/16 created" + - test_seventeen['ip_address']['address'] == "10.10.200.31/16" + - test_seventeen['ip_address']['family'] == 4 + - test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_seventeen['ip_address']['assigned_object_id'] == 4 + +- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + prefix: 10.10.0.0/16 + interface: + name: GigabitEthernet2 + device: test100 + state: new + register: test_eighteen + +- name: 18 - ASSERT + ansible.builtin.assert: + that: + - test_eighteen is changed + - test_eighteen['diff']['before']['state'] == "absent" + - test_eighteen['diff']['after']['state'] == "present" + - test_eighteen['msg'] == "ip_address 10.10.0.2/16 created" + - test_eighteen['ip_address']['address'] == "10.10.0.2/16" + - test_eighteen['ip_address']['family'] == 4 + - test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_eighteen['ip_address']['assigned_object_id'] == 4 diff --git a/tests/integration/targets/v3.7/tasks/netbox_ip_address.yml b/tests/integration/targets/v3.7/tasks/netbox_ip_address.yml index 8813f8dc..328cdfc3 100644 --- a/tests/integration/targets/v3.7/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v3.7/tasks/netbox_ip_address.yml @@ -350,3 +350,52 @@ - test_sixteen['diff']['after']['state'] == "present" - test_sixteen['msg'] == "ip_address 10.120.10.1/32 created" - test_sixteen['ip_address']['address'] == "10.120.10.1/32" + +- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + address: 10.10.200.31/16 + interface: + device: test100 + name: GigabitEthernet2 + register: test_seventeen + +- name: 17 - ASSERT + ansible.builtin.assert: + that: + - test_seventeen is changed + - test_seventeen['diff']['before']['state'] == "absent" + - test_seventeen['diff']['after']['state'] == "present" + - test_seventeen['msg'] == "ip_address 10.10.200.31/16 created" + - test_seventeen['ip_address']['address'] == "10.10.200.31/16" + - test_seventeen['ip_address']['family'] == 4 + - test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_seventeen['ip_address']['assigned_object_id'] == 4 + +- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + prefix: 10.10.0.0/16 + interface: + name: GigabitEthernet2 + device: test100 + state: new + register: test_eighteen + +- name: 18 - ASSERT + ansible.builtin.assert: + that: + - test_eighteen is changed + - test_eighteen['diff']['before']['state'] == "absent" + - test_eighteen['diff']['after']['state'] == "present" + - test_eighteen['msg'] == "ip_address 10.10.0.2/16 created" + - test_eighteen['ip_address']['address'] == "10.10.0.2/16" + - test_eighteen['ip_address']['family'] == 4 + - test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_eighteen['ip_address']['assigned_object_id'] == 4 diff --git a/tests/integration/targets/v4.0/tasks/netbox_ip_address.yml b/tests/integration/targets/v4.0/tasks/netbox_ip_address.yml index 8813f8dc..328cdfc3 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_ip_address.yml @@ -350,3 +350,52 @@ - test_sixteen['diff']['after']['state'] == "present" - test_sixteen['msg'] == "ip_address 10.120.10.1/32 created" - test_sixteen['ip_address']['address'] == "10.120.10.1/32" + +- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + address: 10.10.200.31/16 + interface: + device: test100 + name: GigabitEthernet2 + register: test_seventeen + +- name: 17 - ASSERT + ansible.builtin.assert: + that: + - test_seventeen is changed + - test_seventeen['diff']['before']['state'] == "absent" + - test_seventeen['diff']['after']['state'] == "present" + - test_seventeen['msg'] == "ip_address 10.10.200.31/16 created" + - test_seventeen['ip_address']['address'] == "10.10.200.31/16" + - test_seventeen['ip_address']['family'] == 4 + - test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_seventeen['ip_address']['assigned_object_id'] == 4 + +- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + prefix: 10.10.0.0/16 + interface: + name: GigabitEthernet2 + device: test100 + state: new + register: test_eighteen + +- name: 18 - ASSERT + ansible.builtin.assert: + that: + - test_eighteen is changed + - test_eighteen['diff']['before']['state'] == "absent" + - test_eighteen['diff']['after']['state'] == "present" + - test_eighteen['msg'] == "ip_address 10.10.0.2/16 created" + - test_eighteen['ip_address']['address'] == "10.10.0.2/16" + - test_eighteen['ip_address']['family'] == 4 + - test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_eighteen['ip_address']['assigned_object_id'] == 4 diff --git a/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml b/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml index 8813f8dc..328cdfc3 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml @@ -350,3 +350,52 @@ - test_sixteen['diff']['after']['state'] == "present" - test_sixteen['msg'] == "ip_address 10.120.10.1/32 created" - test_sixteen['ip_address']['address'] == "10.120.10.1/32" + +- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + address: 10.10.200.31/16 + interface: + device: test100 + name: GigabitEthernet2 + register: test_seventeen + +- name: 17 - ASSERT + ansible.builtin.assert: + that: + - test_seventeen is changed + - test_seventeen['diff']['before']['state'] == "absent" + - test_seventeen['diff']['after']['state'] == "present" + - test_seventeen['msg'] == "ip_address 10.10.200.31/16 created" + - test_seventeen['ip_address']['address'] == "10.10.200.31/16" + - test_seventeen['ip_address']['family'] == 4 + - test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_seventeen['ip_address']['assigned_object_id'] == 4 + +- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + prefix: 10.10.0.0/16 + interface: + name: GigabitEthernet2 + device: test100 + state: new + register: test_eighteen + +- name: 18 - ASSERT + ansible.builtin.assert: + that: + - test_eighteen is changed + - test_eighteen['diff']['before']['state'] == "absent" + - test_eighteen['diff']['after']['state'] == "present" + - test_eighteen['msg'] == "ip_address 10.10.0.2/16 created" + - test_eighteen['ip_address']['address'] == "10.10.0.2/16" + - test_eighteen['ip_address']['family'] == 4 + - test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_eighteen['ip_address']['assigned_object_id'] == 4