From a6d0d3c63b4064b89c1476531568d8ffb49cff9b Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:31:32 +0300 Subject: [PATCH 01/27] changed the interface to be an ID --- plugins/module_utils/netbox_ipam.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/module_utils/netbox_ipam.py b/plugins/module_utils/netbox_ipam.py index f8a0131dc..166a6e340 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) From 0cbd5b01c2cd8a3b4f7a5294bcd13d5932f4d23f Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:43:49 +0300 Subject: [PATCH 02/27] changed single quetes to duble quetes --- plugins/module_utils/netbox_ipam.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/netbox_ipam.py b/plugins/module_utils/netbox_ipam.py index 166a6e340..40bc09825 100644 --- a/plugins/module_utils/netbox_ipam.py +++ b/plugins/module_utils/netbox_ipam.py @@ -207,8 +207,8 @@ def run(self): if self.endpoint == "ip_addresses": if 'interface' in data: - data["assigned_object_id"] = data['interface'] - data['assigned_object_type'] = "dcim.interface" + data["assigned_object_id"] = data["interface"] + data["assigned_object_type"] = "dcim.interface" if self.endpoint in SLUG_REQUIRED: if not data.get("slug"): From 3b2e3c50456dd44d0f2782d89c6392fa14cc523c Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Fri, 20 Sep 2024 23:10:14 +0300 Subject: [PATCH 03/27] changed single quetes to duble quetes --- plugins/module_utils/netbox_ipam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/netbox_ipam.py b/plugins/module_utils/netbox_ipam.py index 40bc09825..8d1b731f4 100644 --- a/plugins/module_utils/netbox_ipam.py +++ b/plugins/module_utils/netbox_ipam.py @@ -206,7 +206,7 @@ def run(self): name = data.get("name") if self.endpoint == "ip_addresses": - if 'interface' in data: + if "interface" in data: data["assigned_object_id"] = data["interface"] data["assigned_object_type"] = "dcim.interface" From 874e04aeb7c8f955056dfd5b825e2ae68cc6a729 Mon Sep 17 00:00:00 2001 From: Tobias Lindenberg Date: Fri, 2 Dec 2022 09:35:20 +0100 Subject: [PATCH 04/27] Add custom headers to inventory request --- plugins/inventory/nb_inventory.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/inventory/nb_inventory.py b/plugins/inventory/nb_inventory.py index 678a41798..71c55860e 100644 --- a/plugins/inventory/nb_inventory.py +++ b/plugins/inventory/nb_inventory.py @@ -264,6 +264,10 @@ - By default, the inventory hostname is the netbox device name - If set, sets the inventory hostname from this field in custom_fields instead default: False + headers: + description: Dictionary of headers to be passed to the NetBox API. + type: dict + default: {} """ EXAMPLES = """ @@ -281,6 +285,8 @@ device_query_filters: - has_primary_ip: 'true' - tenant__n: internal +headers: + Cookie: "{{ auth_cookie }}" # has_primary_ip is a useful way to filter out patch panels and other passive devices # Adding '__n' to a field searches for the negation of the value. @@ -2142,6 +2148,7 @@ def parse(self, inventory, loader, path, cache=True): "User-Agent": "ansible %s Python %s" % (ansible_version, python_version.split(" ", maxsplit=1)[0]), "Content-type": "application/json", + **self.get_option("headers"), } self.cert = self.get_option("cert") self.key = self.get_option("key") From 32698f6e0914cec764931b5afd0a940703b71683 Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Sat, 21 Sep 2024 15:11:04 -0400 Subject: [PATCH 05/27] Support headers environment variable for inventory plugin --- plugins/inventory/nb_inventory.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/inventory/nb_inventory.py b/plugins/inventory/nb_inventory.py index 71c55860e..e62f47e9b 100644 --- a/plugins/inventory/nb_inventory.py +++ b/plugins/inventory/nb_inventory.py @@ -266,8 +266,9 @@ default: False headers: description: Dictionary of headers to be passed to the NetBox API. - type: dict default: {} + env: + - name: NETBOX_HEADERS """ EXAMPLES = """ @@ -2121,6 +2122,12 @@ def _set_authorization(self): ) else: self.headers.update({"Authorization": "Token %s" % token}) + headers = self.get_option("headers") + if headers: + if isinstance(headers, str): + headers = json.loads(headers) + if isinstance(headers, dict): + self.headers.update(headers) def parse(self, inventory, loader, path, cache=True): super(InventoryModule, self).parse(inventory, loader, path) @@ -2148,7 +2155,6 @@ def parse(self, inventory, loader, path, cache=True): "User-Agent": "ansible %s Python %s" % (ansible_version, python_version.split(" ", maxsplit=1)[0]), "Content-type": "application/json", - **self.get_option("headers"), } self.cert = self.get_option("cert") self.key = self.get_option("key") From 6aba9233a343844df9bb97afb900a0ca460e0e83 Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Fri, 20 Sep 2024 20:57:51 -0400 Subject: [PATCH 06/27] support custom headers in lookup plugin --- plugins/lookup/nb_lookup.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/lookup/nb_lookup.py b/plugins/lookup/nb_lookup.py index 99de7323a..9483eb6ae 100644 --- a/plugins/lookup/nb_lookup.py +++ b/plugins/lookup/nb_lookup.py @@ -51,6 +51,11 @@ - name: NETBOX_TOKEN - name: NETBOX_API_TOKEN required: false + headers: + description: Dictionary of headers to be passed to the NetBox API. + default: {} + env: + - name: NETBOX_HEADERS validate_certs: description: - Whether or not to validate SSL of the NetBox instance @@ -108,6 +113,7 @@ import os import functools +import json from pprint import pformat from ansible.errors import AnsibleError @@ -411,6 +417,7 @@ def run(self, terms, variables=None, **kwargs): or os.getenv("NETBOX_API") or os.getenv("NETBOX_URL") ) + netbox_headers = kwargs.get("headers") or os.getenv("NETBOX_HEADERS") or {} netbox_ssl_verify = kwargs.get("validate_certs", True) netbox_private_key = kwargs.get("private_key") netbox_private_key_file = kwargs.get("key_file") @@ -421,8 +428,12 @@ def run(self, terms, variables=None, **kwargs): if not isinstance(terms, list): terms = [terms] + if isinstance(netbox_headers, str): + netbox_headers = json.loads(netbox_headers) + try: session = requests.Session() + session.headers = netbox_headers session.verify = netbox_ssl_verify if Version(version("pynetbox")) < Version("7.0.0"): From 7b9df55e85679ca42990da920e5c2cfd44b26be8 Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Thu, 26 Sep 2024 00:40:48 -0400 Subject: [PATCH 07/27] add changelog for #1327 --- changelogs/fragments/1327-add-custom-headers.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/1327-add-custom-headers.yml diff --git a/changelogs/fragments/1327-add-custom-headers.yml b/changelogs/fragments/1327-add-custom-headers.yml new file mode 100644 index 000000000..b13f56c89 --- /dev/null +++ b/changelogs/fragments/1327-add-custom-headers.yml @@ -0,0 +1,2 @@ +minor_changes: + - Add support for custom headers From fefd4da7affe292b8f97accdf011f18f6f6fa175 Mon Sep 17 00:00:00 2001 From: Johan Guldmyr Date: Thu, 3 Oct 2024 11:05:30 +0300 Subject: [PATCH 08/27] nb_lookup.py: Add example for lookup with variable --- .../fragments/1312-add-hostname_field-option.yml | 2 ++ plugins/lookup/nb_lookup.py | 14 ++++++++++++++ .../targets/v4.1/tasks/netbox_lookup.yml | 15 +++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 changelogs/fragments/1312-add-hostname_field-option.yml diff --git a/changelogs/fragments/1312-add-hostname_field-option.yml b/changelogs/fragments/1312-add-hostname_field-option.yml new file mode 100644 index 000000000..5efcba69f --- /dev/null +++ b/changelogs/fragments/1312-add-hostname_field-option.yml @@ -0,0 +1,2 @@ +minor_changes: + - Add example for using ansible variables in lookup diff --git a/plugins/lookup/nb_lookup.py b/plugins/lookup/nb_lookup.py index 99de7323a..3200074ae 100644 --- a/plugins/lookup/nb_lookup.py +++ b/plugins/lookup/nb_lookup.py @@ -97,6 +97,20 @@ api_endpoint='http://localhost/', api_filter='role=management tag=Dell'), token='') }}" + # This example uses an API Filter with a variable and jinja concatenation + - name: Set hostname fact + set_fact: + hostname: "my-server" + - name: Obtain details of a single device from NetBox + debug: + msg: > + "Device {{item.0.value.display}} (ID: {{item.0.key}}) was + manufactured by {{ item.0.value.device_type.manufacturer.name }}" + loop: + - '{{ query("netbox.netbox.nb_lookup", "devices", + api_endpoint="http://localhost/", + api_filter="name=" ~hostname, + token="") }}' """ RETURN = """ diff --git a/tests/integration/targets/v4.1/tasks/netbox_lookup.yml b/tests/integration/targets/v4.1/tasks/netbox_lookup.yml index 3d54e02b1..046f327eb 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_lookup.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_lookup.yml @@ -88,3 +88,18 @@ vars: query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" + +- name: "NETBOX_LOOKUP 11: Device query by ansible variable" + ansible.builtin.set_fact: + hostname: "L2" + +- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox" + ansible.builtin.debug: + msg: > + "Device {{item.0.value.display}} (ID: {{item.0.key}}) was + manufactured by {{ item.0.value.device_type.manufacturer.name }}" + loop: + - '{{ query("netbox.netbox.nb_lookup", "devices", + api_filter="name=" ~hostname, + api_endpoint="http://localhost:32768", + token="0123456789abcdef0123456789abcdef01234567") }}' From dd976fcc920610349b71a96ae2eea67105fb1075 Mon Sep 17 00:00:00 2001 From: Johan Guldmyr Date: Thu, 10 Oct 2024 13:23:52 +0300 Subject: [PATCH 09/27] nb_lookup: tests for v3.5-v4.0 too Keeps the lookup files of v3.5 and v4.1 identical. --- ...ion.yml => 1332-add-hostname_field-option.yml} | 0 .../targets/v3.5/tasks/netbox_lookup.yml | 15 +++++++++++++++ .../targets/v3.6/tasks/netbox_lookup.yml | 15 +++++++++++++++ .../targets/v3.7/tasks/netbox_lookup.yml | 15 +++++++++++++++ .../targets/v4.0/tasks/netbox_lookup.yml | 15 +++++++++++++++ 5 files changed, 60 insertions(+) rename changelogs/fragments/{1312-add-hostname_field-option.yml => 1332-add-hostname_field-option.yml} (100%) diff --git a/changelogs/fragments/1312-add-hostname_field-option.yml b/changelogs/fragments/1332-add-hostname_field-option.yml similarity index 100% rename from changelogs/fragments/1312-add-hostname_field-option.yml rename to changelogs/fragments/1332-add-hostname_field-option.yml diff --git a/tests/integration/targets/v3.5/tasks/netbox_lookup.yml b/tests/integration/targets/v3.5/tasks/netbox_lookup.yml index 3d54e02b1..046f327eb 100644 --- a/tests/integration/targets/v3.5/tasks/netbox_lookup.yml +++ b/tests/integration/targets/v3.5/tasks/netbox_lookup.yml @@ -88,3 +88,18 @@ vars: query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" + +- name: "NETBOX_LOOKUP 11: Device query by ansible variable" + ansible.builtin.set_fact: + hostname: "L2" + +- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox" + ansible.builtin.debug: + msg: > + "Device {{item.0.value.display}} (ID: {{item.0.key}}) was + manufactured by {{ item.0.value.device_type.manufacturer.name }}" + loop: + - '{{ query("netbox.netbox.nb_lookup", "devices", + api_filter="name=" ~hostname, + api_endpoint="http://localhost:32768", + token="0123456789abcdef0123456789abcdef01234567") }}' diff --git a/tests/integration/targets/v3.6/tasks/netbox_lookup.yml b/tests/integration/targets/v3.6/tasks/netbox_lookup.yml index 3d54e02b1..046f327eb 100644 --- a/tests/integration/targets/v3.6/tasks/netbox_lookup.yml +++ b/tests/integration/targets/v3.6/tasks/netbox_lookup.yml @@ -88,3 +88,18 @@ vars: query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" + +- name: "NETBOX_LOOKUP 11: Device query by ansible variable" + ansible.builtin.set_fact: + hostname: "L2" + +- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox" + ansible.builtin.debug: + msg: > + "Device {{item.0.value.display}} (ID: {{item.0.key}}) was + manufactured by {{ item.0.value.device_type.manufacturer.name }}" + loop: + - '{{ query("netbox.netbox.nb_lookup", "devices", + api_filter="name=" ~hostname, + api_endpoint="http://localhost:32768", + token="0123456789abcdef0123456789abcdef01234567") }}' diff --git a/tests/integration/targets/v3.7/tasks/netbox_lookup.yml b/tests/integration/targets/v3.7/tasks/netbox_lookup.yml index 3d54e02b1..046f327eb 100644 --- a/tests/integration/targets/v3.7/tasks/netbox_lookup.yml +++ b/tests/integration/targets/v3.7/tasks/netbox_lookup.yml @@ -88,3 +88,18 @@ vars: query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" + +- name: "NETBOX_LOOKUP 11: Device query by ansible variable" + ansible.builtin.set_fact: + hostname: "L2" + +- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox" + ansible.builtin.debug: + msg: > + "Device {{item.0.value.display}} (ID: {{item.0.key}}) was + manufactured by {{ item.0.value.device_type.manufacturer.name }}" + loop: + - '{{ query("netbox.netbox.nb_lookup", "devices", + api_filter="name=" ~hostname, + api_endpoint="http://localhost:32768", + token="0123456789abcdef0123456789abcdef01234567") }}' diff --git a/tests/integration/targets/v4.0/tasks/netbox_lookup.yml b/tests/integration/targets/v4.0/tasks/netbox_lookup.yml index 3d54e02b1..046f327eb 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_lookup.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_lookup.yml @@ -88,3 +88,18 @@ vars: query_result: "{{ query('netbox.netbox.nb_lookup', 'devices', api_filter='id=1', api_endpoint='http://localhost:32768', token='0123456789abcdef0123456789abcdef01234567') }}" + +- name: "NETBOX_LOOKUP 11: Device query by ansible variable" + ansible.builtin.set_fact: + hostname: "L2" + +- name: "NETBOX LOOKUP 11.1: Obtain details of a single device from NetBox" + ansible.builtin.debug: + msg: > + "Device {{item.0.value.display}} (ID: {{item.0.key}}) was + manufactured by {{ item.0.value.device_type.manufacturer.name }}" + loop: + - '{{ query("netbox.netbox.nb_lookup", "devices", + api_filter="name=" ~hostname, + api_endpoint="http://localhost:32768", + token="0123456789abcdef0123456789abcdef01234567") }}' From 0d255cd867c239fd7e2a7512592d921803202ada Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 14:57:55 +0300 Subject: [PATCH 10/27] added integration tests to the interface value in v4.1 --- .../targets/v4.1/tasks/netbox_ip_address.yml | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) 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 8813f8dcb..f8de3b167 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,99 @@ - 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 with interface value - test100 - State: present" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + address: 10.10.200.30/16 + interface: + name: GigabitEthernet2 + device: test100 + register: test_nine + +- name: 17 - ASSERT + ansible.builtin.assert: + that: + - test_nine is changed + - test_nine['diff']['before']['state'] == "absent" + - test_nine['diff']['after']['state'] == "present" + - test_nine['msg'] == "ip_address 10.10.200.30/16 created" + - test_nine['ip_address']['address'] == "10.10.200.30/16" + - test_nine['ip_address']['family'] == 4 + - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" + - test_nine['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 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_ten + +- name: 18 - ASSERT + ansible.builtin.assert: + that: + - test_ten is changed + - test_ten['diff']['before']['state'] == "absent" + - test_ten['diff']['after']['state'] == "present" + - test_ten['msg'] == "ip_address 10.10.0.1/16 created" + - test_ten['ip_address']['address'] == "10.10.0.1/16" + - test_ten['ip_address']['family'] == 4 + - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" + - test_ten['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 4 + +- name: "19 - 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 + prefix: 192.168.100.0/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_eleven + +- name: 19 - ASSERT + ansible.builtin.assert: + that: + - test_eleven is changed + - test_eleven['diff']['before']['state'] == "absent" + - test_eleven['diff']['after']['state'] == "present" + - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" + - test_eleven['ip_address']['address'] == "192.168.100.2/24" + - test_nine['ip_address']['interface'] == 4 + +- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + address: 192.168.100.2/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_twelve + +- name: 20 - ASSERT + ansible.builtin.assert: + that: + - not test_twelve['changed'] + - test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists" + - test_twelve['ip_address']['address'] == "192.168.100.2/24" + - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" + - test_twelve['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 4 From f2847fec65a8f2f3ad30a002e1d46d22d5e2c42d Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 15:01:19 +0300 Subject: [PATCH 11/27] added integration tests to the interface value in v4.0 --- .../targets/v4.0/tasks/netbox_ip_address.yml | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) 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 8813f8dcb..f8de3b167 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,99 @@ - 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 with interface value - test100 - State: present" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + address: 10.10.200.30/16 + interface: + name: GigabitEthernet2 + device: test100 + register: test_nine + +- name: 17 - ASSERT + ansible.builtin.assert: + that: + - test_nine is changed + - test_nine['diff']['before']['state'] == "absent" + - test_nine['diff']['after']['state'] == "present" + - test_nine['msg'] == "ip_address 10.10.200.30/16 created" + - test_nine['ip_address']['address'] == "10.10.200.30/16" + - test_nine['ip_address']['family'] == 4 + - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" + - test_nine['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 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_ten + +- name: 18 - ASSERT + ansible.builtin.assert: + that: + - test_ten is changed + - test_ten['diff']['before']['state'] == "absent" + - test_ten['diff']['after']['state'] == "present" + - test_ten['msg'] == "ip_address 10.10.0.1/16 created" + - test_ten['ip_address']['address'] == "10.10.0.1/16" + - test_ten['ip_address']['family'] == 4 + - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" + - test_ten['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 4 + +- name: "19 - 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 + prefix: 192.168.100.0/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_eleven + +- name: 19 - ASSERT + ansible.builtin.assert: + that: + - test_eleven is changed + - test_eleven['diff']['before']['state'] == "absent" + - test_eleven['diff']['after']['state'] == "present" + - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" + - test_eleven['ip_address']['address'] == "192.168.100.2/24" + - test_nine['ip_address']['interface'] == 4 + +- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + address: 192.168.100.2/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_twelve + +- name: 20 - ASSERT + ansible.builtin.assert: + that: + - not test_twelve['changed'] + - test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists" + - test_twelve['ip_address']['address'] == "192.168.100.2/24" + - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" + - test_twelve['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 4 From 426dd3d56a83d23b8cf3812048b414fd44301015 Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 15:03:42 +0300 Subject: [PATCH 12/27] added integration tests to the interface value in v3.7, v3.6, v3.5 --- .../targets/v3.5/tasks/netbox_ip_address.yml | 96 +++++++++++++++++++ .../targets/v3.6/tasks/netbox_ip_address.yml | 96 +++++++++++++++++++ .../targets/v3.7/tasks/netbox_ip_address.yml | 96 +++++++++++++++++++ 3 files changed, 288 insertions(+) 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 ce2b125a4..b92a1e873 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,99 @@ - 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 with interface value - test100 - State: present" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + address: 10.10.200.30/16 + interface: + name: GigabitEthernet2 + device: test100 + register: test_nine + +- name: 17 - ASSERT + ansible.builtin.assert: + that: + - test_nine is changed + - test_nine['diff']['before']['state'] == "absent" + - test_nine['diff']['after']['state'] == "present" + - test_nine['msg'] == "ip_address 10.10.200.30/16 created" + - test_nine['ip_address']['address'] == "10.10.200.30/16" + - test_nine['ip_address']['family'] == 4 + - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" + - test_nine['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 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_ten + +- name: 18 - ASSERT + ansible.builtin.assert: + that: + - test_ten is changed + - test_ten['diff']['before']['state'] == "absent" + - test_ten['diff']['after']['state'] == "present" + - test_ten['msg'] == "ip_address 10.10.0.1/16 created" + - test_ten['ip_address']['address'] == "10.10.0.1/16" + - test_ten['ip_address']['family'] == 4 + - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" + - test_ten['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 4 + +- name: "19 - 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 + prefix: 192.168.100.0/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_eleven + +- name: 19 - ASSERT + ansible.builtin.assert: + that: + - test_eleven is changed + - test_eleven['diff']['before']['state'] == "absent" + - test_eleven['diff']['after']['state'] == "present" + - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" + - test_eleven['ip_address']['address'] == "192.168.100.2/24" + - test_nine['ip_address']['interface'] == 4 + +- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + address: 192.168.100.2/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_twelve + +- name: 20 - ASSERT + ansible.builtin.assert: + that: + - not test_twelve['changed'] + - test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists" + - test_twelve['ip_address']['address'] == "192.168.100.2/24" + - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" + - test_twelve['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 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 ce2b125a4..b92a1e873 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,99 @@ - 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 with interface value - test100 - State: present" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + address: 10.10.200.30/16 + interface: + name: GigabitEthernet2 + device: test100 + register: test_nine + +- name: 17 - ASSERT + ansible.builtin.assert: + that: + - test_nine is changed + - test_nine['diff']['before']['state'] == "absent" + - test_nine['diff']['after']['state'] == "present" + - test_nine['msg'] == "ip_address 10.10.200.30/16 created" + - test_nine['ip_address']['address'] == "10.10.200.30/16" + - test_nine['ip_address']['family'] == 4 + - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" + - test_nine['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 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_ten + +- name: 18 - ASSERT + ansible.builtin.assert: + that: + - test_ten is changed + - test_ten['diff']['before']['state'] == "absent" + - test_ten['diff']['after']['state'] == "present" + - test_ten['msg'] == "ip_address 10.10.0.1/16 created" + - test_ten['ip_address']['address'] == "10.10.0.1/16" + - test_ten['ip_address']['family'] == 4 + - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" + - test_ten['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 4 + +- name: "19 - 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 + prefix: 192.168.100.0/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_eleven + +- name: 19 - ASSERT + ansible.builtin.assert: + that: + - test_eleven is changed + - test_eleven['diff']['before']['state'] == "absent" + - test_eleven['diff']['after']['state'] == "present" + - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" + - test_eleven['ip_address']['address'] == "192.168.100.2/24" + - test_nine['ip_address']['interface'] == 4 + +- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + address: 192.168.100.2/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_twelve + +- name: 20 - ASSERT + ansible.builtin.assert: + that: + - not test_twelve['changed'] + - test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists" + - test_twelve['ip_address']['address'] == "192.168.100.2/24" + - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" + - test_twelve['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 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 8813f8dcb..f8de3b167 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,99 @@ - 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 with interface value - test100 - State: present" + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + family: 4 + address: 10.10.200.30/16 + interface: + name: GigabitEthernet2 + device: test100 + register: test_nine + +- name: 17 - ASSERT + ansible.builtin.assert: + that: + - test_nine is changed + - test_nine['diff']['before']['state'] == "absent" + - test_nine['diff']['after']['state'] == "present" + - test_nine['msg'] == "ip_address 10.10.200.30/16 created" + - test_nine['ip_address']['address'] == "10.10.200.30/16" + - test_nine['ip_address']['family'] == 4 + - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" + - test_nine['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 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_ten + +- name: 18 - ASSERT + ansible.builtin.assert: + that: + - test_ten is changed + - test_ten['diff']['before']['state'] == "absent" + - test_ten['diff']['after']['state'] == "present" + - test_ten['msg'] == "ip_address 10.10.0.1/16 created" + - test_ten['ip_address']['address'] == "10.10.0.1/16" + - test_ten['ip_address']['family'] == 4 + - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" + - test_ten['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 4 + +- name: "19 - 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 + prefix: 192.168.100.0/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_eleven + +- name: 19 - ASSERT + ansible.builtin.assert: + that: + - test_eleven is changed + - test_eleven['diff']['before']['state'] == "absent" + - test_eleven['diff']['after']['state'] == "present" + - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" + - test_eleven['ip_address']['address'] == "192.168.100.2/24" + - test_nine['ip_address']['interface'] == 4 + +- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + address: 192.168.100.2/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_twelve + +- name: 20 - ASSERT + ansible.builtin.assert: + that: + - not test_twelve['changed'] + - test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists" + - test_twelve['ip_address']['address'] == "192.168.100.2/24" + - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" + - test_twelve['ip_address']['assigned_object_id'] == 4 + - test_nine['ip_address']['interface'] == 4 From d243b87976ee5b707ba661e87bf311d31c16aa15 Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 15:14:18 +0300 Subject: [PATCH 13/27] added a change fragment --- changelogs/fragments/1323-fixing-bug-#975.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/1323-fixing-bug-#975.yml diff --git a/changelogs/fragments/1323-fixing-bug-#975.yml b/changelogs/fragments/1323-fixing-bug-#975.yml new file mode 100644 index 000000000..558892274 --- /dev/null +++ b/changelogs/fragments/1323-fixing-bug-#975.yml @@ -0,0 +1,3 @@ +bugfixes: + - netbox_ip_address - Fixed the problem preventing assignment of an IP address to a network interface + [#1323](https://github.com/netbox-community/ansible_modules/pull/1323) \ No newline at end of file From 5f0f65953e26f9a8f36aa804a46719c3dfddbf15 Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 15:26:20 +0300 Subject: [PATCH 14/27] changed some linting errors --- changelogs/fragments/1323-fixing-bug-#975.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelogs/fragments/1323-fixing-bug-#975.yml b/changelogs/fragments/1323-fixing-bug-#975.yml index 558892274..b8390e86f 100644 --- a/changelogs/fragments/1323-fixing-bug-#975.yml +++ b/changelogs/fragments/1323-fixing-bug-#975.yml @@ -1,3 +1,3 @@ bugfixes: - - netbox_ip_address - Fixed the problem preventing assignment of an IP address to a network interface - [#1323](https://github.com/netbox-community/ansible_modules/pull/1323) \ No newline at end of file + - netbox_ip_address - Fixed the problem preventing assignment of an IP address to a network interface + [#1323](https://github.com/netbox-community/ansible_modules/pull/1323) From e9d3b2f7c9cea9a53275a3960d945a752bcd8a60 Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 15:32:40 +0300 Subject: [PATCH 15/27] made a change to v4.1 testing to see if this was the issue --- tests/integration/targets/v4.1/tasks/netbox_ip_address.yml | 4 ---- 1 file changed, 4 deletions(-) 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 f8de3b167..9dbf51491 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml @@ -374,7 +374,6 @@ - test_nine['ip_address']['family'] == 4 - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" - test_nine['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 4 - name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new" netbox.netbox.netbox_ip_address: @@ -400,7 +399,6 @@ - test_ten['ip_address']['family'] == 4 - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" - test_ten['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 4 - name: "19 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present" netbox.netbox.netbox_ip_address: @@ -423,7 +421,6 @@ - test_eleven['diff']['after']['state'] == "present" - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" - test_eleven['ip_address']['address'] == "192.168.100.2/24" - - test_nine['ip_address']['interface'] == 4 - name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value netbox.netbox.netbox_ip_address: @@ -445,4 +442,3 @@ - test_twelve['ip_address']['address'] == "192.168.100.2/24" - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" - test_twelve['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 4 From e2302c9b6888d2a8344047c2488c10d7c1dcb55a Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 15:54:38 +0300 Subject: [PATCH 16/27] rolled back the tests I added --- .../targets/v3.5/tasks/netbox_ip_address.yml | 96 ------------------- .../targets/v3.6/tasks/netbox_ip_address.yml | 96 ------------------- .../targets/v3.7/tasks/netbox_ip_address.yml | 96 ------------------- .../targets/v4.0/tasks/netbox_ip_address.yml | 96 ------------------- .../targets/v4.1/tasks/netbox_ip_address.yml | 92 ------------------ 5 files changed, 476 deletions(-) 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 b92a1e873..ce2b125a4 100644 --- a/tests/integration/targets/v3.5/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v3.5/tasks/netbox_ip_address.yml @@ -348,99 +348,3 @@ - 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 with interface value - test100 - State: present" - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - family: 4 - address: 10.10.200.30/16 - interface: - name: GigabitEthernet2 - device: test100 - register: test_nine - -- name: 17 - ASSERT - ansible.builtin.assert: - that: - - test_nine is changed - - test_nine['diff']['before']['state'] == "absent" - - test_nine['diff']['after']['state'] == "present" - - test_nine['msg'] == "ip_address 10.10.200.30/16 created" - - test_nine['ip_address']['address'] == "10.10.200.30/16" - - test_nine['ip_address']['family'] == 4 - - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" - - test_nine['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 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_ten - -- name: 18 - ASSERT - ansible.builtin.assert: - that: - - test_ten is changed - - test_ten['diff']['before']['state'] == "absent" - - test_ten['diff']['after']['state'] == "present" - - test_ten['msg'] == "ip_address 10.10.0.1/16 created" - - test_ten['ip_address']['address'] == "10.10.0.1/16" - - test_ten['ip_address']['family'] == 4 - - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" - - test_ten['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 4 - -- name: "19 - 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 - prefix: 192.168.100.0/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_eleven - -- name: 19 - ASSERT - ansible.builtin.assert: - that: - - test_eleven is changed - - test_eleven['diff']['before']['state'] == "absent" - - test_eleven['diff']['after']['state'] == "present" - - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" - - test_eleven['ip_address']['address'] == "192.168.100.2/24" - - test_nine['ip_address']['interface'] == 4 - -- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - address: 192.168.100.2/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_twelve - -- name: 20 - ASSERT - ansible.builtin.assert: - that: - - not test_twelve['changed'] - - test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists" - - test_twelve['ip_address']['address'] == "192.168.100.2/24" - - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" - - test_twelve['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 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 b92a1e873..ce2b125a4 100644 --- a/tests/integration/targets/v3.6/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v3.6/tasks/netbox_ip_address.yml @@ -348,99 +348,3 @@ - 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 with interface value - test100 - State: present" - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - family: 4 - address: 10.10.200.30/16 - interface: - name: GigabitEthernet2 - device: test100 - register: test_nine - -- name: 17 - ASSERT - ansible.builtin.assert: - that: - - test_nine is changed - - test_nine['diff']['before']['state'] == "absent" - - test_nine['diff']['after']['state'] == "present" - - test_nine['msg'] == "ip_address 10.10.200.30/16 created" - - test_nine['ip_address']['address'] == "10.10.200.30/16" - - test_nine['ip_address']['family'] == 4 - - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" - - test_nine['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 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_ten - -- name: 18 - ASSERT - ansible.builtin.assert: - that: - - test_ten is changed - - test_ten['diff']['before']['state'] == "absent" - - test_ten['diff']['after']['state'] == "present" - - test_ten['msg'] == "ip_address 10.10.0.1/16 created" - - test_ten['ip_address']['address'] == "10.10.0.1/16" - - test_ten['ip_address']['family'] == 4 - - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" - - test_ten['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 4 - -- name: "19 - 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 - prefix: 192.168.100.0/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_eleven - -- name: 19 - ASSERT - ansible.builtin.assert: - that: - - test_eleven is changed - - test_eleven['diff']['before']['state'] == "absent" - - test_eleven['diff']['after']['state'] == "present" - - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" - - test_eleven['ip_address']['address'] == "192.168.100.2/24" - - test_nine['ip_address']['interface'] == 4 - -- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - address: 192.168.100.2/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_twelve - -- name: 20 - ASSERT - ansible.builtin.assert: - that: - - not test_twelve['changed'] - - test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists" - - test_twelve['ip_address']['address'] == "192.168.100.2/24" - - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" - - test_twelve['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 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 f8de3b167..8813f8dcb 100644 --- a/tests/integration/targets/v3.7/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v3.7/tasks/netbox_ip_address.yml @@ -350,99 +350,3 @@ - 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 with interface value - test100 - State: present" - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - family: 4 - address: 10.10.200.30/16 - interface: - name: GigabitEthernet2 - device: test100 - register: test_nine - -- name: 17 - ASSERT - ansible.builtin.assert: - that: - - test_nine is changed - - test_nine['diff']['before']['state'] == "absent" - - test_nine['diff']['after']['state'] == "present" - - test_nine['msg'] == "ip_address 10.10.200.30/16 created" - - test_nine['ip_address']['address'] == "10.10.200.30/16" - - test_nine['ip_address']['family'] == 4 - - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" - - test_nine['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 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_ten - -- name: 18 - ASSERT - ansible.builtin.assert: - that: - - test_ten is changed - - test_ten['diff']['before']['state'] == "absent" - - test_ten['diff']['after']['state'] == "present" - - test_ten['msg'] == "ip_address 10.10.0.1/16 created" - - test_ten['ip_address']['address'] == "10.10.0.1/16" - - test_ten['ip_address']['family'] == 4 - - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" - - test_ten['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 4 - -- name: "19 - 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 - prefix: 192.168.100.0/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_eleven - -- name: 19 - ASSERT - ansible.builtin.assert: - that: - - test_eleven is changed - - test_eleven['diff']['before']['state'] == "absent" - - test_eleven['diff']['after']['state'] == "present" - - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" - - test_eleven['ip_address']['address'] == "192.168.100.2/24" - - test_nine['ip_address']['interface'] == 4 - -- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - address: 192.168.100.2/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_twelve - -- name: 20 - ASSERT - ansible.builtin.assert: - that: - - not test_twelve['changed'] - - test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists" - - test_twelve['ip_address']['address'] == "192.168.100.2/24" - - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" - - test_twelve['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 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 f8de3b167..8813f8dcb 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_ip_address.yml @@ -350,99 +350,3 @@ - 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 with interface value - test100 - State: present" - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - family: 4 - address: 10.10.200.30/16 - interface: - name: GigabitEthernet2 - device: test100 - register: test_nine - -- name: 17 - ASSERT - ansible.builtin.assert: - that: - - test_nine is changed - - test_nine['diff']['before']['state'] == "absent" - - test_nine['diff']['after']['state'] == "present" - - test_nine['msg'] == "ip_address 10.10.200.30/16 created" - - test_nine['ip_address']['address'] == "10.10.200.30/16" - - test_nine['ip_address']['family'] == 4 - - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" - - test_nine['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 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_ten - -- name: 18 - ASSERT - ansible.builtin.assert: - that: - - test_ten is changed - - test_ten['diff']['before']['state'] == "absent" - - test_ten['diff']['after']['state'] == "present" - - test_ten['msg'] == "ip_address 10.10.0.1/16 created" - - test_ten['ip_address']['address'] == "10.10.0.1/16" - - test_ten['ip_address']['family'] == 4 - - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" - - test_ten['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 4 - -- name: "19 - 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 - prefix: 192.168.100.0/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_eleven - -- name: 19 - ASSERT - ansible.builtin.assert: - that: - - test_eleven is changed - - test_eleven['diff']['before']['state'] == "absent" - - test_eleven['diff']['after']['state'] == "present" - - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" - - test_eleven['ip_address']['address'] == "192.168.100.2/24" - - test_nine['ip_address']['interface'] == 4 - -- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - address: 192.168.100.2/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_twelve - -- name: 20 - ASSERT - ansible.builtin.assert: - that: - - not test_twelve['changed'] - - test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists" - - test_twelve['ip_address']['address'] == "192.168.100.2/24" - - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" - - test_twelve['ip_address']['assigned_object_id'] == 4 - - test_nine['ip_address']['interface'] == 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 9dbf51491..8813f8dcb 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml @@ -350,95 +350,3 @@ - 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 with interface value - test100 - State: present" - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - family: 4 - address: 10.10.200.30/16 - interface: - name: GigabitEthernet2 - device: test100 - register: test_nine - -- name: 17 - ASSERT - ansible.builtin.assert: - that: - - test_nine is changed - - test_nine['diff']['before']['state'] == "absent" - - test_nine['diff']['after']['state'] == "present" - - test_nine['msg'] == "ip_address 10.10.200.30/16 created" - - test_nine['ip_address']['address'] == "10.10.200.30/16" - - test_nine['ip_address']['family'] == 4 - - test_nine['ip_address']['assigned_object_type'] == "dcim.interface" - - test_nine['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_ten - -- name: 18 - ASSERT - ansible.builtin.assert: - that: - - test_ten is changed - - test_ten['diff']['before']['state'] == "absent" - - test_ten['diff']['after']['state'] == "present" - - test_ten['msg'] == "ip_address 10.10.0.1/16 created" - - test_ten['ip_address']['address'] == "10.10.0.1/16" - - test_ten['ip_address']['family'] == 4 - - test_ten['ip_address']['assigned_object_type'] == "dcim.interface" - - test_ten['ip_address']['assigned_object_id'] == 4 - -- name: "19 - 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 - prefix: 192.168.100.0/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_eleven - -- name: 19 - ASSERT - ansible.builtin.assert: - that: - - test_eleven is changed - - test_eleven['diff']['before']['state'] == "absent" - - test_eleven['diff']['after']['state'] == "present" - - test_eleven['msg'] == "ip_address 192.168.100.2/24 created" - - test_eleven['ip_address']['address'] == "192.168.100.2/24" - -- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - address: 192.168.100.2/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_twelve - -- name: 20 - ASSERT - ansible.builtin.assert: - that: - - not test_twelve['changed'] - - test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists" - - test_twelve['ip_address']['address'] == "192.168.100.2/24" - - test_twelve['ip_address']['assigned_object_type'] == "dcim.interface" - - test_twelve['ip_address']['assigned_object_id'] == 4 From 1d5b592a76dac1b3448f670ccd44ce2a2c0f525f Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 15:57:24 +0300 Subject: [PATCH 17/27] added a simple test to see if it would work. this interface should exist and the ip 10.10.200.31/16 should be added to it --- .../targets/v4.1/tasks/netbox_ip_address.yml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 8813f8dcb..ddbb9cb2e 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,27 @@ - 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: 9 - 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 From 6eb1e5d7e53d57da196adffc56fa970246d8f71b Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:24:15 +0300 Subject: [PATCH 18/27] added some more tests to v4.1 --- .../targets/v4.1/tasks/netbox_ip_address.yml | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) 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 ddbb9cb2e..832786e12 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml @@ -363,7 +363,7 @@ name: GigabitEthernet2 register: test_seventeen -- name: 9 - ASSERT +- name: 17 - ASSERT ansible.builtin.assert: that: - test_seventeen is changed @@ -374,3 +374,71 @@ - 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.1/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 + +- name: "19 - 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 + prefix: 192.168.100.0/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_nineteen + +- name: 19 - ASSERT + ansible.builtin.assert: + that: + - test_nineteen is changed + - test_nineteen['diff']['before']['state'] == "absent" + - test_nineteen['diff']['after']['state'] == "present" + - test_nineteen['msg'] == "ip_address 192.168.100.3/24 created" + - test_nineteen['ip_address']['address'] == "192.168.100.3/24" + +- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value + netbox.netbox.netbox_ip_address: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + address: 192.168.100.2/24 + interface: + name: GigabitEthernet2 + device: test100 + state: present + register: test_twenty + +- name: 20 - ASSERT + ansible.builtin.assert: + that: + - not test_twenty['changed'] + - test_twenty['msg'] == "ip_address 192.168.100.2/24 already exists" + - test_twenty['ip_address']['address'] == "192.168.100.2/24" + - test_twenty['ip_address']['assigned_object_type'] == "dcim.interface" + - test_twenty['ip_address']['assigned_object_id'] == 4 From 5d96e8dcdad4b68ec356fbe09700b5d327870832 Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:35:06 +0300 Subject: [PATCH 19/27] fixed the 18'th test --- tests/integration/targets/v4.1/tasks/netbox_ip_address.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 832786e12..a9ceb1395 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml @@ -395,7 +395,7 @@ - test_eighteen['diff']['before']['state'] == "absent" - test_eighteen['diff']['after']['state'] == "present" - test_eighteen['msg'] == "ip_address 10.10.0.1/16 created" - - test_eighteen['ip_address']['address'] == "10.10.0.2/16" + - test_eighteen['ip_address']['address'] == "10.10.0.1/16" - test_eighteen['ip_address']['family'] == 4 - test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface" - test_eighteen['ip_address']['assigned_object_id'] == 4 From 9b7ddccd8d3134de93842d110f95b018bca36744 Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:45:44 +0300 Subject: [PATCH 20/27] fixed the 18'th test again --- tests/integration/targets/v4.1/tasks/netbox_ip_address.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 a9ceb1395..3cace03b0 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml @@ -394,8 +394,8 @@ - test_eighteen is changed - test_eighteen['diff']['before']['state'] == "absent" - test_eighteen['diff']['after']['state'] == "present" - - test_eighteen['msg'] == "ip_address 10.10.0.1/16 created" - - test_eighteen['ip_address']['address'] == "10.10.0.1/16" + - 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 From 2aaeb760fe4fa34b8e217def77005217f982bf85 Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:59:26 +0300 Subject: [PATCH 21/27] fixed test 19 --- tests/integration/targets/v4.1/tasks/netbox_ip_address.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 3cace03b0..986c3be3c 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml @@ -406,7 +406,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: family: 4 - prefix: 192.168.100.0/24 + prefix: 192.168.101.0/24 interface: name: GigabitEthernet2 device: test100 @@ -419,8 +419,8 @@ - test_nineteen is changed - test_nineteen['diff']['before']['state'] == "absent" - test_nineteen['diff']['after']['state'] == "present" - - test_nineteen['msg'] == "ip_address 192.168.100.3/24 created" - - test_nineteen['ip_address']['address'] == "192.168.100.3/24" + - test_nineteen['msg'] == "ip_address 192.168.101.1/24 created" + - test_nineteen['ip_address']['address'] == "192.168.101.1/24" - name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value netbox.netbox.netbox_ip_address: From 4a3c2c2bf5c78c7b2b21c0209d50cb845720caaa Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:11:55 +0300 Subject: [PATCH 22/27] fixed test 19 --- .../integration/targets/v4.1/tasks/netbox_ip_address.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 986c3be3c..c864ea3e4 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml @@ -406,7 +406,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: family: 4 - prefix: 192.168.101.0/24 + prefix: 10.120.10.0/24 interface: name: GigabitEthernet2 device: test100 @@ -419,8 +419,10 @@ - test_nineteen is changed - test_nineteen['diff']['before']['state'] == "absent" - test_nineteen['diff']['after']['state'] == "present" - - test_nineteen['msg'] == "ip_address 192.168.101.1/24 created" - - test_nineteen['ip_address']['address'] == "192.168.101.1/24" + - test_nineteen['msg'] == "ip_address 10.120.10.2/24 created" + - test_nineteen['ip_address']['address'] == "10.120.10.2/24" + - test_nineteen['ip_address']['assigned_object_type'] == "dcim.interface" + - test_nineteen['ip_address']['assigned_object_id'] == 4 - name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value netbox.netbox.netbox_ip_address: From bd3968c5e8e555955117d3e6feee5999a8a2b85e Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:33:38 +0300 Subject: [PATCH 23/27] removed the unnecessary tests. --- .../targets/v4.1/tasks/netbox_ip_address.yml | 45 ------------------- 1 file changed, 45 deletions(-) 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 c864ea3e4..328cdfc35 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_ip_address.yml @@ -399,48 +399,3 @@ - test_eighteen['ip_address']['family'] == 4 - test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface" - test_eighteen['ip_address']['assigned_object_id'] == 4 - -- name: "19 - 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 - prefix: 10.120.10.0/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_nineteen - -- name: 19 - ASSERT - ansible.builtin.assert: - that: - - test_nineteen is changed - - test_nineteen['diff']['before']['state'] == "absent" - - test_nineteen['diff']['after']['state'] == "present" - - test_nineteen['msg'] == "ip_address 10.120.10.2/24 created" - - test_nineteen['ip_address']['address'] == "10.120.10.2/24" - - test_nineteen['ip_address']['assigned_object_type'] == "dcim.interface" - - test_nineteen['ip_address']['assigned_object_id'] == 4 - -- name: 20 - Duplicate - 192.168.100.2/24 on interface with interface value - netbox.netbox.netbox_ip_address: - netbox_url: http://localhost:32768 - netbox_token: "0123456789abcdef0123456789abcdef01234567" - data: - address: 192.168.100.2/24 - interface: - name: GigabitEthernet2 - device: test100 - state: present - register: test_twenty - -- name: 20 - ASSERT - ansible.builtin.assert: - that: - - not test_twenty['changed'] - - test_twenty['msg'] == "ip_address 192.168.100.2/24 already exists" - - test_twenty['ip_address']['address'] == "192.168.100.2/24" - - test_twenty['ip_address']['assigned_object_type'] == "dcim.interface" - - test_twenty['ip_address']['assigned_object_id'] == 4 From 6bf3aa51e695ea9927b0da891f2fce7d34fa3cac Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:35:51 +0300 Subject: [PATCH 24/27] added the tests to 4.0, 3.7, 3.6, 3.5 --- .../targets/v3.5/tasks/netbox_ip_address.yml | 49 +++++++++++++++++++ .../targets/v3.6/tasks/netbox_ip_address.yml | 49 +++++++++++++++++++ .../targets/v3.7/tasks/netbox_ip_address.yml | 49 +++++++++++++++++++ .../targets/v4.0/tasks/netbox_ip_address.yml | 49 +++++++++++++++++++ 4 files changed, 196 insertions(+) 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 ce2b125a4..c73fb9dfb 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 ce2b125a4..c73fb9dfb 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 8813f8dcb..328cdfc35 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 8813f8dcb..328cdfc35 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 From df4ba57813e73a52355794fa1a5d7f23e69381b4 Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:43:00 +0300 Subject: [PATCH 25/27] removed the pull request ref --- changelogs/fragments/1323-fixing-bug-#975.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/1323-fixing-bug-#975.yml b/changelogs/fragments/1323-fixing-bug-#975.yml index b8390e86f..c002348ed 100644 --- a/changelogs/fragments/1323-fixing-bug-#975.yml +++ b/changelogs/fragments/1323-fixing-bug-#975.yml @@ -1,3 +1,3 @@ bugfixes: - netbox_ip_address - Fixed the problem preventing assignment of an IP address to a network interface - [#1323](https://github.com/netbox-community/ansible_modules/pull/1323) + From e7b6ca54f4b5c584c13e371217413e016dde0551 Mon Sep 17 00:00:00 2001 From: Ido Don <76511079+Ido-Don@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:43:36 +0300 Subject: [PATCH 26/27] removed the extra line --- changelogs/fragments/1323-fixing-bug-#975.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/changelogs/fragments/1323-fixing-bug-#975.yml b/changelogs/fragments/1323-fixing-bug-#975.yml index c002348ed..c0ac8b423 100644 --- a/changelogs/fragments/1323-fixing-bug-#975.yml +++ b/changelogs/fragments/1323-fixing-bug-#975.yml @@ -1,3 +1,2 @@ bugfixes: - netbox_ip_address - Fixed the problem preventing assignment of an IP address to a network interface - From 72ecbb8efff8d68cbe2cf53c92798da90cb813a3 Mon Sep 17 00:00:00 2001 From: Alexander Nikitin Date: Mon, 14 Oct 2024 14:13:20 +0300 Subject: [PATCH 27/27] fix issue 1335 --- changelogs/fragments/1335-api-status-page-not-found.yml | 2 ++ plugins/inventory/nb_inventory.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/1335-api-status-page-not-found.yml diff --git a/changelogs/fragments/1335-api-status-page-not-found.yml b/changelogs/fragments/1335-api-status-page-not-found.yml new file mode 100644 index 000000000..14c90a600 --- /dev/null +++ b/changelogs/fragments/1335-api-status-page-not-found.yml @@ -0,0 +1,2 @@ +bugfixes: + - fix call /api/status/ instead /api/status in nb_inventory plugin. (https://github.com/netbox-community/ansible_modules/issues/1335). diff --git a/plugins/inventory/nb_inventory.py b/plugins/inventory/nb_inventory.py index e62f47e9b..b06d0fa7f 100644 --- a/plugins/inventory/nb_inventory.py +++ b/plugins/inventory/nb_inventory.py @@ -1607,7 +1607,7 @@ def fetch_api_docs(self): cached_api_version = None cache = None - status = self._fetch_information(self.api_endpoint + "/api/status") + status = self._fetch_information(self.api_endpoint + "/api/status/") netbox_api_version = ".".join(status["netbox-version"].split(".")[:2]) if version.parse(netbox_api_version) >= version.parse("3.5.0"):