From bce96243a3a3c2014501674c29ecc4d5128ca7f8 Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 28 Aug 2024 14:26:58 -0400 Subject: [PATCH 1/2] Allow location_type to use name for lookup Currently location_types that use the name to reference the related object will always report as "changed" since it compares the name with the ID of the existing location_type. Updated to convert name to ID. --- plugins/module_utils/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/module_utils/utils.py b/plugins/module_utils/utils.py index 979c6a8f..56b8f45e 100644 --- a/plugins/module_utils/utils.py +++ b/plugins/module_utils/utils.py @@ -112,6 +112,7 @@ installed_device="name", import_targets="name", location="name", + location_type="name", manufacturer="name", master="name", nat_inside="address", @@ -175,6 +176,7 @@ "ipaddresses": "ip_addresses", "lag": "interfaces", "location": "locations", + "location_type": "location_types", "manufacturer": "manufacturers", "master": "devices", "nat_inside": "ip_addresses", From ec336578637573ebf865ab5f4b960697fbc4beb1 Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 28 Aug 2024 14:51:30 -0400 Subject: [PATCH 2/2] Add test cases --- tests/integration/targets/latest/tasks/location.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/integration/targets/latest/tasks/location.yml b/tests/integration/targets/latest/tasks/location.yml index 64eed8fa..4b6650ae 100644 --- a/tests/integration/targets/latest/tasks/location.yml +++ b/tests/integration/targets/latest/tasks/location.yml @@ -50,7 +50,7 @@ url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: Test Location - location_type: "{{ parent_location_type['key'] }}" + location_type: "{{ parent_location_type['value']['name'] }}" description: Test Location Description register: test_update @@ -69,7 +69,7 @@ name: Test Location 2 status: Active description: Test Location 2 Description - location_type: "{{ child_location_type['key'] }}" + location_type: "{{ child_location_type['value']['name'] }}" parent_location: "{{ test_create_min['location']['id'] }}" tenant: Test Tenant facility: EquinoxCA7 @@ -106,7 +106,7 @@ name: Test Location 2 status: Active description: Test Location 2 Description - location_type: "{{ child_location_type['key'] }}" + location_type: "{{ child_location_type['value']['name'] }}" parent: "{{ test_create_min['location']['id'] }}" tenant: Test Tenant facility: EquinoxCA7 @@ -167,7 +167,6 @@ - set_fact: fist_location: "{{ lookup('networktocode.nautobot.lookup', 'locations', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Test Location\" location_type=\"My Parent Location Type\"') }}" - - name: "8 - Delete location" networktocode.nautobot.location: url: "{{ nautobot_url }}"