From a7d57cc68c8f0c601dc660f6e4ed3cfc70ce4146 Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Sat, 23 Aug 2025 11:00:29 -0400 Subject: [PATCH 01/10] Remove useless NB_CONFIG constant --- plugins/module_utils/netbox_users.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/module_utils/netbox_users.py b/plugins/module_utils/netbox_users.py index 5d3d2f2a0..3786e0354 100644 --- a/plugins/module_utils/netbox_users.py +++ b/plugins/module_utils/netbox_users.py @@ -10,7 +10,6 @@ ENDPOINT_NAME_MAPPING, ) -NB_CONFIG = "config" NB_GROUPS = "groups" NB_PERMISSIONS = "permissions" NB_TOKENS = "tokens" @@ -26,7 +25,6 @@ def run(self): This function should have all necessary code for endpoints within the application to create/update/delete the endpoint objects Supported endpoints: - - config - groups - permissions - tokens From a8571e8ec40a4d594f64f316c5927edbc611d1ac Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Sat, 23 Aug 2025 11:02:15 -0400 Subject: [PATCH 02/10] Clarify netbox_users.py data flow a bit --- plugins/module_utils/netbox_users.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/module_utils/netbox_users.py b/plugins/module_utils/netbox_users.py index 3786e0354..91ca510b6 100644 --- a/plugins/module_utils/netbox_users.py +++ b/plugins/module_utils/netbox_users.py @@ -70,14 +70,17 @@ def run(self): self.module.exit_json(**self.result) def _update_netbox_object(self, data): - if self.endpoint == "users": - return self._update_netbox_user(data) + if self.endpoint == NB_TOKENS: + return self._update_netbox_token(data) else: - if self.endpoint == "tokens" and "key" in data: - del data["key"] - return super()._update_netbox_object(data) + return self.__update_netbox_object__(data) - def _update_netbox_user(self, data): + def _update_netbox_token(self, data): + if "key" in data: + del data["key"] + return self.__update_netbox_object__(data) + + def __update_netbox_object__(self, data): serialized_nb_obj = self.nb_object.serialize() updated_obj = serialized_nb_obj.copy() updated_obj.update(data) From cdd59dc7e61b31e3f94774e49f5c313c7915a742 Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Sat, 23 Aug 2025 11:02:38 -0400 Subject: [PATCH 03/10] Treat permissions, groups, actions, and object types as sets These suboptions of users, user groups, and permissions were previously compared as lists for the purposes of updates, and so would update the object whenever the order would change. --- plugins/module_utils/netbox_users.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/module_utils/netbox_users.py b/plugins/module_utils/netbox_users.py index 91ca510b6..d8d2880da 100644 --- a/plugins/module_utils/netbox_users.py +++ b/plugins/module_utils/netbox_users.py @@ -15,6 +15,9 @@ NB_TOKENS = "tokens" NB_USERS = "users" +# These suboptions are lists, but need to be modeled as sets for comparison purposes. +LIST_AS_SET_KEYS = set(["permissions", "groups", "actions", "object_types"]) + class NetboxUsersModule(NetboxModule): def __init__(self, module, endpoint): @@ -85,6 +88,12 @@ def __update_netbox_object__(self, data): updated_obj = serialized_nb_obj.copy() updated_obj.update(data) + if serialized_nb_obj: + for key in LIST_AS_SET_KEYS: + if serialized_nb_obj.get(key) and data.get(key): + serialized_nb_obj[key] = set(serialized_nb_obj[key]) + updated_obj[key] = set(data[key]) + if serialized_nb_obj == updated_obj: return serialized_nb_obj, None else: From 7b3a6dd8d234683cbabbd6d20ae3ec0a6795513c Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Sat, 23 Aug 2025 11:05:29 -0400 Subject: [PATCH 04/10] New permission tests --- .../targets/v4.0/tasks/netbox_permission.yml | 47 ++++++++++++++++++ .../targets/v4.1/tasks/netbox_permission.yml | 49 ++++++++++++++++++- .../targets/v4.2/tasks/netbox_permission.yml | 49 ++++++++++++++++++- .../targets/v4.3/tasks/netbox_permission.yml | 49 ++++++++++++++++++- 4 files changed, 191 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/v4.0/tasks/netbox_permission.yml b/tests/integration/targets/v4.0/tasks/netbox_permission.yml index fdc459332..f6119c209 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_permission.yml @@ -167,3 +167,50 @@ - not test_eight['changed'] - test_eight['permission'] == None - test_eight['msg'] == "permission Test Permission already absent" + +- name: "PERMISSION 9: Necessary permission" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission + description: The test permission + enabled: true + actions: + - view + - add + - change + - delete + - extreme_administration + object_types: + - vpn.tunneltermination + - wireless.wirelesslan + state: present + +- name: "PERMISSION 9: Re-create permission with lists in wrong order" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission + description: The test permission + enabled: true + actions: + - extreme_administration + - delete + - change + - add + - view + object_types: + - wireless.wirelesslan + - vpn.tunneltermination + state: present + register: test_nine + +- name: "PERMISSION 9: ASSERT - The same lists in a new order do not update the permission" + ansible.builtin.assert: + that: + - not test_nine['changed'] + # actions seem to be ordered randomly so we cannot test them here + - test_nine['permission']['object_types'][0] == 'vpn.tunneltermination' + - test_nine['permission']['object_types'][1] == 'wireless.wirelesslan' diff --git a/tests/integration/targets/v4.1/tasks/netbox_permission.yml b/tests/integration/targets/v4.1/tasks/netbox_permission.yml index 865991142..f6119c209 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_permission.yml @@ -123,7 +123,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword2 + password: TestPassword permissions: - Test Permission 2 state: present @@ -167,3 +167,50 @@ - not test_eight['changed'] - test_eight['permission'] == None - test_eight['msg'] == "permission Test Permission already absent" + +- name: "PERMISSION 9: Necessary permission" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission + description: The test permission + enabled: true + actions: + - view + - add + - change + - delete + - extreme_administration + object_types: + - vpn.tunneltermination + - wireless.wirelesslan + state: present + +- name: "PERMISSION 9: Re-create permission with lists in wrong order" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission + description: The test permission + enabled: true + actions: + - extreme_administration + - delete + - change + - add + - view + object_types: + - wireless.wirelesslan + - vpn.tunneltermination + state: present + register: test_nine + +- name: "PERMISSION 9: ASSERT - The same lists in a new order do not update the permission" + ansible.builtin.assert: + that: + - not test_nine['changed'] + # actions seem to be ordered randomly so we cannot test them here + - test_nine['permission']['object_types'][0] == 'vpn.tunneltermination' + - test_nine['permission']['object_types'][1] == 'wireless.wirelesslan' diff --git a/tests/integration/targets/v4.2/tasks/netbox_permission.yml b/tests/integration/targets/v4.2/tasks/netbox_permission.yml index 865991142..f6119c209 100644 --- a/tests/integration/targets/v4.2/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.2/tasks/netbox_permission.yml @@ -123,7 +123,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword2 + password: TestPassword permissions: - Test Permission 2 state: present @@ -167,3 +167,50 @@ - not test_eight['changed'] - test_eight['permission'] == None - test_eight['msg'] == "permission Test Permission already absent" + +- name: "PERMISSION 9: Necessary permission" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission + description: The test permission + enabled: true + actions: + - view + - add + - change + - delete + - extreme_administration + object_types: + - vpn.tunneltermination + - wireless.wirelesslan + state: present + +- name: "PERMISSION 9: Re-create permission with lists in wrong order" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission + description: The test permission + enabled: true + actions: + - extreme_administration + - delete + - change + - add + - view + object_types: + - wireless.wirelesslan + - vpn.tunneltermination + state: present + register: test_nine + +- name: "PERMISSION 9: ASSERT - The same lists in a new order do not update the permission" + ansible.builtin.assert: + that: + - not test_nine['changed'] + # actions seem to be ordered randomly so we cannot test them here + - test_nine['permission']['object_types'][0] == 'vpn.tunneltermination' + - test_nine['permission']['object_types'][1] == 'wireless.wirelesslan' diff --git a/tests/integration/targets/v4.3/tasks/netbox_permission.yml b/tests/integration/targets/v4.3/tasks/netbox_permission.yml index 865991142..f6119c209 100644 --- a/tests/integration/targets/v4.3/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.3/tasks/netbox_permission.yml @@ -123,7 +123,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword2 + password: TestPassword permissions: - Test Permission 2 state: present @@ -167,3 +167,50 @@ - not test_eight['changed'] - test_eight['permission'] == None - test_eight['msg'] == "permission Test Permission already absent" + +- name: "PERMISSION 9: Necessary permission" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission + description: The test permission + enabled: true + actions: + - view + - add + - change + - delete + - extreme_administration + object_types: + - vpn.tunneltermination + - wireless.wirelesslan + state: present + +- name: "PERMISSION 9: Re-create permission with lists in wrong order" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission + description: The test permission + enabled: true + actions: + - extreme_administration + - delete + - change + - add + - view + object_types: + - wireless.wirelesslan + - vpn.tunneltermination + state: present + register: test_nine + +- name: "PERMISSION 9: ASSERT - The same lists in a new order do not update the permission" + ansible.builtin.assert: + that: + - not test_nine['changed'] + # actions seem to be ordered randomly so we cannot test them here + - test_nine['permission']['object_types'][0] == 'vpn.tunneltermination' + - test_nine['permission']['object_types'][1] == 'wireless.wirelesslan' From f09cbc8f4d4cfab3f22c056d3fce9404fd2b8281 Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Sat, 23 Aug 2025 11:12:21 -0400 Subject: [PATCH 05/10] New user tests --- .../targets/v4.0/tasks/netbox_user.yml | 101 ++++++++++++++++- .../targets/v4.1/tasks/netbox_user.yml | 105 +++++++++++++++++- .../targets/v4.2/tasks/netbox_user.yml | 105 +++++++++++++++++- .../targets/v4.3/tasks/netbox_user.yml | 105 +++++++++++++++++- 4 files changed, 402 insertions(+), 14 deletions(-) diff --git a/tests/integration/targets/v4.0/tasks/netbox_user.yml b/tests/integration/targets/v4.0/tasks/netbox_user.yml index a95e93234..e9056934f 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_user.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_user.yml @@ -14,7 +14,7 @@ state: present register: test_one -- name: "USESR 1: ASSERT - Necessary info creation" +- name: "USER 1: ASSERT - Necessary info creation" ansible.builtin.assert: that: - test_one is changed @@ -88,7 +88,7 @@ - test_four['diff']['after']['state'] == "absent" - test_four['msg'] == "user TestUser deleted" -- name: "USER 5: ASSERT - Delete non existing" +- name: "USER 5: Delete non existing" netbox.netbox.netbox_user: netbox_url: http://localhost:32768 netbox_token: "0123456789abcdef0123456789abcdef01234567" @@ -103,3 +103,100 @@ - not test_five['changed'] - test_five['user'] == None - test_five['msg'] == "user TestUser already absent" + +- name: "USER 6: Necessary group 1" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group Alpha + state: present + register: user_group_alpha + +- name: "USER 6: Necessary group 2" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group Beta + state: present + register: user_group_beta + +- name: "User 6: Necessary permission 1" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Foo + actions: + - view + object_types: [] + state: present + register: permission_foo + +- name: "User 6: Necessary permission 2" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Bar + actions: + - view + object_types: [] + state: present + register: permission_bar + +- name: "User 6: Necessary permission 3" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Baz + actions: + - view + object_types: [] + state: present + register: permission_baz + +- name: "USER 6: Set up user with multiple groups and permissions" + netbox.netbox.netbox_user: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + username: TestUser2 + password: TestPassword2 + permissions: + - Test Permission Foo + - Test Permission Bar + - Test Permission Baz + groups: + - Test User Group Alpha + - Test User Group Beta + state: present + +- name: "USER 6: Re-create user with lists in wrong order" + netbox.netbox.netbox_user: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + username: TestUser2 + permissions: + - Test Permission Bar + - Test Permission Baz + - Test Permission Foo + groups: + - Test User Group Beta + - Test User Group Alpha + state: present + register: test_six + +- name: "USER 6: ASSERT - The same lists in a new order do not update the user" + ansible.builtin.assert: + that: + - not test_six['changed'] + - test_six['msg'] == "user TestUser2 already exists" + - test_six['user']['groups'][0] == user_group_alpha['user_group']['id'] + - test_six['user']['groups'][1] == user_group_beta['user_group']['id'] + - test_six['user']['permissions'][0] == permission_foo['permission']['id'] + - test_six['user']['permissions'][1] == permission_bar['permission']['id'] + - test_six['user']['permissions'][2] == permission_baz['permission']['id'] diff --git a/tests/integration/targets/v4.1/tasks/netbox_user.yml b/tests/integration/targets/v4.1/tasks/netbox_user.yml index 360ba6c31..e9056934f 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_user.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_user.yml @@ -10,11 +10,11 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword1 + password: TestPassword state: present register: test_one -- name: "USESR 1: ASSERT - Necessary info creation" +- name: "USER 1: ASSERT - Necessary info creation" ansible.builtin.assert: that: - test_one is changed @@ -48,7 +48,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword1 + password: TestPassword email: test@user.com first_name: Test last_name: User @@ -88,7 +88,7 @@ - test_four['diff']['after']['state'] == "absent" - test_four['msg'] == "user TestUser deleted" -- name: "USER 5: ASSERT - Delete non existing" +- name: "USER 5: Delete non existing" netbox.netbox.netbox_user: netbox_url: http://localhost:32768 netbox_token: "0123456789abcdef0123456789abcdef01234567" @@ -103,3 +103,100 @@ - not test_five['changed'] - test_five['user'] == None - test_five['msg'] == "user TestUser already absent" + +- name: "USER 6: Necessary group 1" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group Alpha + state: present + register: user_group_alpha + +- name: "USER 6: Necessary group 2" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group Beta + state: present + register: user_group_beta + +- name: "User 6: Necessary permission 1" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Foo + actions: + - view + object_types: [] + state: present + register: permission_foo + +- name: "User 6: Necessary permission 2" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Bar + actions: + - view + object_types: [] + state: present + register: permission_bar + +- name: "User 6: Necessary permission 3" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Baz + actions: + - view + object_types: [] + state: present + register: permission_baz + +- name: "USER 6: Set up user with multiple groups and permissions" + netbox.netbox.netbox_user: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + username: TestUser2 + password: TestPassword2 + permissions: + - Test Permission Foo + - Test Permission Bar + - Test Permission Baz + groups: + - Test User Group Alpha + - Test User Group Beta + state: present + +- name: "USER 6: Re-create user with lists in wrong order" + netbox.netbox.netbox_user: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + username: TestUser2 + permissions: + - Test Permission Bar + - Test Permission Baz + - Test Permission Foo + groups: + - Test User Group Beta + - Test User Group Alpha + state: present + register: test_six + +- name: "USER 6: ASSERT - The same lists in a new order do not update the user" + ansible.builtin.assert: + that: + - not test_six['changed'] + - test_six['msg'] == "user TestUser2 already exists" + - test_six['user']['groups'][0] == user_group_alpha['user_group']['id'] + - test_six['user']['groups'][1] == user_group_beta['user_group']['id'] + - test_six['user']['permissions'][0] == permission_foo['permission']['id'] + - test_six['user']['permissions'][1] == permission_bar['permission']['id'] + - test_six['user']['permissions'][2] == permission_baz['permission']['id'] diff --git a/tests/integration/targets/v4.2/tasks/netbox_user.yml b/tests/integration/targets/v4.2/tasks/netbox_user.yml index 360ba6c31..e9056934f 100644 --- a/tests/integration/targets/v4.2/tasks/netbox_user.yml +++ b/tests/integration/targets/v4.2/tasks/netbox_user.yml @@ -10,11 +10,11 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword1 + password: TestPassword state: present register: test_one -- name: "USESR 1: ASSERT - Necessary info creation" +- name: "USER 1: ASSERT - Necessary info creation" ansible.builtin.assert: that: - test_one is changed @@ -48,7 +48,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword1 + password: TestPassword email: test@user.com first_name: Test last_name: User @@ -88,7 +88,7 @@ - test_four['diff']['after']['state'] == "absent" - test_four['msg'] == "user TestUser deleted" -- name: "USER 5: ASSERT - Delete non existing" +- name: "USER 5: Delete non existing" netbox.netbox.netbox_user: netbox_url: http://localhost:32768 netbox_token: "0123456789abcdef0123456789abcdef01234567" @@ -103,3 +103,100 @@ - not test_five['changed'] - test_five['user'] == None - test_five['msg'] == "user TestUser already absent" + +- name: "USER 6: Necessary group 1" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group Alpha + state: present + register: user_group_alpha + +- name: "USER 6: Necessary group 2" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group Beta + state: present + register: user_group_beta + +- name: "User 6: Necessary permission 1" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Foo + actions: + - view + object_types: [] + state: present + register: permission_foo + +- name: "User 6: Necessary permission 2" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Bar + actions: + - view + object_types: [] + state: present + register: permission_bar + +- name: "User 6: Necessary permission 3" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Baz + actions: + - view + object_types: [] + state: present + register: permission_baz + +- name: "USER 6: Set up user with multiple groups and permissions" + netbox.netbox.netbox_user: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + username: TestUser2 + password: TestPassword2 + permissions: + - Test Permission Foo + - Test Permission Bar + - Test Permission Baz + groups: + - Test User Group Alpha + - Test User Group Beta + state: present + +- name: "USER 6: Re-create user with lists in wrong order" + netbox.netbox.netbox_user: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + username: TestUser2 + permissions: + - Test Permission Bar + - Test Permission Baz + - Test Permission Foo + groups: + - Test User Group Beta + - Test User Group Alpha + state: present + register: test_six + +- name: "USER 6: ASSERT - The same lists in a new order do not update the user" + ansible.builtin.assert: + that: + - not test_six['changed'] + - test_six['msg'] == "user TestUser2 already exists" + - test_six['user']['groups'][0] == user_group_alpha['user_group']['id'] + - test_six['user']['groups'][1] == user_group_beta['user_group']['id'] + - test_six['user']['permissions'][0] == permission_foo['permission']['id'] + - test_six['user']['permissions'][1] == permission_bar['permission']['id'] + - test_six['user']['permissions'][2] == permission_baz['permission']['id'] diff --git a/tests/integration/targets/v4.3/tasks/netbox_user.yml b/tests/integration/targets/v4.3/tasks/netbox_user.yml index 360ba6c31..e9056934f 100644 --- a/tests/integration/targets/v4.3/tasks/netbox_user.yml +++ b/tests/integration/targets/v4.3/tasks/netbox_user.yml @@ -10,11 +10,11 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword1 + password: TestPassword state: present register: test_one -- name: "USESR 1: ASSERT - Necessary info creation" +- name: "USER 1: ASSERT - Necessary info creation" ansible.builtin.assert: that: - test_one is changed @@ -48,7 +48,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword1 + password: TestPassword email: test@user.com first_name: Test last_name: User @@ -88,7 +88,7 @@ - test_four['diff']['after']['state'] == "absent" - test_four['msg'] == "user TestUser deleted" -- name: "USER 5: ASSERT - Delete non existing" +- name: "USER 5: Delete non existing" netbox.netbox.netbox_user: netbox_url: http://localhost:32768 netbox_token: "0123456789abcdef0123456789abcdef01234567" @@ -103,3 +103,100 @@ - not test_five['changed'] - test_five['user'] == None - test_five['msg'] == "user TestUser already absent" + +- name: "USER 6: Necessary group 1" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group Alpha + state: present + register: user_group_alpha + +- name: "USER 6: Necessary group 2" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group Beta + state: present + register: user_group_beta + +- name: "User 6: Necessary permission 1" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Foo + actions: + - view + object_types: [] + state: present + register: permission_foo + +- name: "User 6: Necessary permission 2" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Bar + actions: + - view + object_types: [] + state: present + register: permission_bar + +- name: "User 6: Necessary permission 3" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Baz + actions: + - view + object_types: [] + state: present + register: permission_baz + +- name: "USER 6: Set up user with multiple groups and permissions" + netbox.netbox.netbox_user: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + username: TestUser2 + password: TestPassword2 + permissions: + - Test Permission Foo + - Test Permission Bar + - Test Permission Baz + groups: + - Test User Group Alpha + - Test User Group Beta + state: present + +- name: "USER 6: Re-create user with lists in wrong order" + netbox.netbox.netbox_user: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + username: TestUser2 + permissions: + - Test Permission Bar + - Test Permission Baz + - Test Permission Foo + groups: + - Test User Group Beta + - Test User Group Alpha + state: present + register: test_six + +- name: "USER 6: ASSERT - The same lists in a new order do not update the user" + ansible.builtin.assert: + that: + - not test_six['changed'] + - test_six['msg'] == "user TestUser2 already exists" + - test_six['user']['groups'][0] == user_group_alpha['user_group']['id'] + - test_six['user']['groups'][1] == user_group_beta['user_group']['id'] + - test_six['user']['permissions'][0] == permission_foo['permission']['id'] + - test_six['user']['permissions'][1] == permission_bar['permission']['id'] + - test_six['user']['permissions'][2] == permission_baz['permission']['id'] From 9b7e055b5365d66f323b0b666501cd3d666be86d Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Sat, 23 Aug 2025 11:12:36 -0400 Subject: [PATCH 06/10] New user group tests --- .../targets/v4.0/tasks/netbox_user_group.yml | 54 ++++++++++++++++++ .../targets/v4.1/tasks/netbox_user_group.yml | 56 ++++++++++++++++++- .../targets/v4.2/tasks/netbox_user_group.yml | 56 ++++++++++++++++++- .../targets/v4.3/tasks/netbox_user_group.yml | 56 ++++++++++++++++++- 4 files changed, 219 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/v4.0/tasks/netbox_user_group.yml b/tests/integration/targets/v4.0/tasks/netbox_user_group.yml index b6f87059f..9a8869951 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_user_group.yml @@ -125,3 +125,57 @@ - not test_seven['changed'] - test_seven['user_group'] == None - test_seven['msg'] == "user_group Test User Group already absent" + +- name: "USER_GROUP 8: Necessary permission 1" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Foo + actions: + - view + object_types: [] + state: present + register: permission_foo + +- name: "USER_GROUP 8: Necessary permission 2" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Bar + actions: + - view + object_types: [] + state: present + register: permission_bar + +- name: "USER_GROUP 8: Necessary info creation" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group + permissions: + - Test Permission Foo + - Test Permission Bar + state: present + +- name: "USER_GROUP 8: Re-create user group with permissions in wrong order" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group + permissions: + - Test Permission Bar + - Test Permission Foo + state: present + register: test_eight + +- name: "USER_GROUP 8: ASSERT - The same permissions in a new order do not update the group" + ansible.builtin.assert: + that: + - not test_eight is changed + - test_eight['user_group']['permissions'][0] == permission_foo['permission']['id'] + - test_eight['user_group']['permissions'][1] == permission_bar['permission']['id'] diff --git a/tests/integration/targets/v4.1/tasks/netbox_user_group.yml b/tests/integration/targets/v4.1/tasks/netbox_user_group.yml index 03dfbe5e0..9a8869951 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_user_group.yml @@ -81,7 +81,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword2 + password: TestPassword groups: - Test User Group state: present @@ -125,3 +125,57 @@ - not test_seven['changed'] - test_seven['user_group'] == None - test_seven['msg'] == "user_group Test User Group already absent" + +- name: "USER_GROUP 8: Necessary permission 1" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Foo + actions: + - view + object_types: [] + state: present + register: permission_foo + +- name: "USER_GROUP 8: Necessary permission 2" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Bar + actions: + - view + object_types: [] + state: present + register: permission_bar + +- name: "USER_GROUP 8: Necessary info creation" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group + permissions: + - Test Permission Foo + - Test Permission Bar + state: present + +- name: "USER_GROUP 8: Re-create user group with permissions in wrong order" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group + permissions: + - Test Permission Bar + - Test Permission Foo + state: present + register: test_eight + +- name: "USER_GROUP 8: ASSERT - The same permissions in a new order do not update the group" + ansible.builtin.assert: + that: + - not test_eight is changed + - test_eight['user_group']['permissions'][0] == permission_foo['permission']['id'] + - test_eight['user_group']['permissions'][1] == permission_bar['permission']['id'] diff --git a/tests/integration/targets/v4.2/tasks/netbox_user_group.yml b/tests/integration/targets/v4.2/tasks/netbox_user_group.yml index 03dfbe5e0..9a8869951 100644 --- a/tests/integration/targets/v4.2/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.2/tasks/netbox_user_group.yml @@ -81,7 +81,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword2 + password: TestPassword groups: - Test User Group state: present @@ -125,3 +125,57 @@ - not test_seven['changed'] - test_seven['user_group'] == None - test_seven['msg'] == "user_group Test User Group already absent" + +- name: "USER_GROUP 8: Necessary permission 1" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Foo + actions: + - view + object_types: [] + state: present + register: permission_foo + +- name: "USER_GROUP 8: Necessary permission 2" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Bar + actions: + - view + object_types: [] + state: present + register: permission_bar + +- name: "USER_GROUP 8: Necessary info creation" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group + permissions: + - Test Permission Foo + - Test Permission Bar + state: present + +- name: "USER_GROUP 8: Re-create user group with permissions in wrong order" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group + permissions: + - Test Permission Bar + - Test Permission Foo + state: present + register: test_eight + +- name: "USER_GROUP 8: ASSERT - The same permissions in a new order do not update the group" + ansible.builtin.assert: + that: + - not test_eight is changed + - test_eight['user_group']['permissions'][0] == permission_foo['permission']['id'] + - test_eight['user_group']['permissions'][1] == permission_bar['permission']['id'] diff --git a/tests/integration/targets/v4.3/tasks/netbox_user_group.yml b/tests/integration/targets/v4.3/tasks/netbox_user_group.yml index 03dfbe5e0..9a8869951 100644 --- a/tests/integration/targets/v4.3/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.3/tasks/netbox_user_group.yml @@ -81,7 +81,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword2 + password: TestPassword groups: - Test User Group state: present @@ -125,3 +125,57 @@ - not test_seven['changed'] - test_seven['user_group'] == None - test_seven['msg'] == "user_group Test User Group already absent" + +- name: "USER_GROUP 8: Necessary permission 1" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Foo + actions: + - view + object_types: [] + state: present + register: permission_foo + +- name: "USER_GROUP 8: Necessary permission 2" + netbox.netbox.netbox_permission: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test Permission Bar + actions: + - view + object_types: [] + state: present + register: permission_bar + +- name: "USER_GROUP 8: Necessary info creation" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group + permissions: + - Test Permission Foo + - Test Permission Bar + state: present + +- name: "USER_GROUP 8: Re-create user group with permissions in wrong order" + netbox.netbox.netbox_user_group: + netbox_url: http://localhost:32768 + netbox_token: "0123456789abcdef0123456789abcdef01234567" + data: + name: Test User Group + permissions: + - Test Permission Bar + - Test Permission Foo + state: present + register: test_eight + +- name: "USER_GROUP 8: ASSERT - The same permissions in a new order do not update the group" + ansible.builtin.assert: + that: + - not test_eight is changed + - test_eight['user_group']['permissions'][0] == permission_foo['permission']['id'] + - test_eight['user_group']['permissions'][1] == permission_bar['permission']['id'] From 2c3c513742998f19a48e9865987ba8ce52990483 Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Sat, 23 Aug 2025 12:15:00 -0400 Subject: [PATCH 07/10] Add numerals to all test passwords --- tests/integration/targets/v4.0/tasks/netbox_permission.yml | 2 +- tests/integration/targets/v4.0/tasks/netbox_token.yml | 2 +- tests/integration/targets/v4.0/tasks/netbox_user.yml | 4 ++-- tests/integration/targets/v4.0/tasks/netbox_user_group.yml | 2 +- tests/integration/targets/v4.1/tasks/netbox_permission.yml | 2 +- tests/integration/targets/v4.1/tasks/netbox_user.yml | 4 ++-- tests/integration/targets/v4.1/tasks/netbox_user_group.yml | 2 +- tests/integration/targets/v4.2/tasks/netbox_permission.yml | 2 +- tests/integration/targets/v4.2/tasks/netbox_user.yml | 4 ++-- tests/integration/targets/v4.2/tasks/netbox_user_group.yml | 2 +- tests/integration/targets/v4.3/tasks/netbox_permission.yml | 2 +- tests/integration/targets/v4.3/tasks/netbox_user.yml | 4 ++-- tests/integration/targets/v4.3/tasks/netbox_user_group.yml | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/integration/targets/v4.0/tasks/netbox_permission.yml b/tests/integration/targets/v4.0/tasks/netbox_permission.yml index f6119c209..86d6a02bb 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_permission.yml @@ -123,7 +123,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword6 permissions: - Test Permission 2 state: present diff --git a/tests/integration/targets/v4.0/tasks/netbox_token.yml b/tests/integration/targets/v4.0/tasks/netbox_token.yml index f149ef9c0..63524494a 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_token.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_token.yml @@ -10,7 +10,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword1 state: present - name: "TOKEN 1: Necessary info creation" diff --git a/tests/integration/targets/v4.0/tasks/netbox_user.yml b/tests/integration/targets/v4.0/tasks/netbox_user.yml index e9056934f..62b35e563 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_user.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_user.yml @@ -10,7 +10,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword1 state: present register: test_one @@ -48,7 +48,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword3 email: test@user.com first_name: Test last_name: User diff --git a/tests/integration/targets/v4.0/tasks/netbox_user_group.yml b/tests/integration/targets/v4.0/tasks/netbox_user_group.yml index 9a8869951..21a79ae19 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_user_group.yml @@ -81,7 +81,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword5 groups: - Test User Group state: present diff --git a/tests/integration/targets/v4.1/tasks/netbox_permission.yml b/tests/integration/targets/v4.1/tasks/netbox_permission.yml index f6119c209..86d6a02bb 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_permission.yml @@ -123,7 +123,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword6 permissions: - Test Permission 2 state: present diff --git a/tests/integration/targets/v4.1/tasks/netbox_user.yml b/tests/integration/targets/v4.1/tasks/netbox_user.yml index e9056934f..62b35e563 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_user.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_user.yml @@ -10,7 +10,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword1 state: present register: test_one @@ -48,7 +48,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword3 email: test@user.com first_name: Test last_name: User diff --git a/tests/integration/targets/v4.1/tasks/netbox_user_group.yml b/tests/integration/targets/v4.1/tasks/netbox_user_group.yml index 9a8869951..21a79ae19 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_user_group.yml @@ -81,7 +81,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword5 groups: - Test User Group state: present diff --git a/tests/integration/targets/v4.2/tasks/netbox_permission.yml b/tests/integration/targets/v4.2/tasks/netbox_permission.yml index f6119c209..86d6a02bb 100644 --- a/tests/integration/targets/v4.2/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.2/tasks/netbox_permission.yml @@ -123,7 +123,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword6 permissions: - Test Permission 2 state: present diff --git a/tests/integration/targets/v4.2/tasks/netbox_user.yml b/tests/integration/targets/v4.2/tasks/netbox_user.yml index e9056934f..62b35e563 100644 --- a/tests/integration/targets/v4.2/tasks/netbox_user.yml +++ b/tests/integration/targets/v4.2/tasks/netbox_user.yml @@ -10,7 +10,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword1 state: present register: test_one @@ -48,7 +48,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword3 email: test@user.com first_name: Test last_name: User diff --git a/tests/integration/targets/v4.2/tasks/netbox_user_group.yml b/tests/integration/targets/v4.2/tasks/netbox_user_group.yml index 9a8869951..21a79ae19 100644 --- a/tests/integration/targets/v4.2/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.2/tasks/netbox_user_group.yml @@ -81,7 +81,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword5 groups: - Test User Group state: present diff --git a/tests/integration/targets/v4.3/tasks/netbox_permission.yml b/tests/integration/targets/v4.3/tasks/netbox_permission.yml index f6119c209..86d6a02bb 100644 --- a/tests/integration/targets/v4.3/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.3/tasks/netbox_permission.yml @@ -123,7 +123,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword6 permissions: - Test Permission 2 state: present diff --git a/tests/integration/targets/v4.3/tasks/netbox_user.yml b/tests/integration/targets/v4.3/tasks/netbox_user.yml index e9056934f..62b35e563 100644 --- a/tests/integration/targets/v4.3/tasks/netbox_user.yml +++ b/tests/integration/targets/v4.3/tasks/netbox_user.yml @@ -10,7 +10,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword1 state: present register: test_one @@ -48,7 +48,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword3 email: test@user.com first_name: Test last_name: User diff --git a/tests/integration/targets/v4.3/tasks/netbox_user_group.yml b/tests/integration/targets/v4.3/tasks/netbox_user_group.yml index 9a8869951..21a79ae19 100644 --- a/tests/integration/targets/v4.3/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.3/tasks/netbox_user_group.yml @@ -81,7 +81,7 @@ netbox_token: "0123456789abcdef0123456789abcdef01234567" data: username: TestUser - password: TestPassword + password: TestPassword5 groups: - Test User Group state: present From 29769164fdbe564cc3046cd92f0ebe70ea12b3bc Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Sat, 23 Aug 2025 12:48:45 -0400 Subject: [PATCH 08/10] Use explicit ID in user group test --- tests/integration/targets/v4.0/tasks/netbox_user_group.yml | 2 +- tests/integration/targets/v4.1/tasks/netbox_user_group.yml | 2 +- tests/integration/targets/v4.2/tasks/netbox_user_group.yml | 2 +- tests/integration/targets/v4.3/tasks/netbox_user_group.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/targets/v4.0/tasks/netbox_user_group.yml b/tests/integration/targets/v4.0/tasks/netbox_user_group.yml index 21a79ae19..0bedc95fb 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_user_group.yml @@ -91,7 +91,7 @@ ansible.builtin.assert: that: - test_five is changed - - test_five['user']['groups'] == [1] + - test_five['user']['groups'] == [test_one['user_group']['id']] - name: "USER_GROUP 6: Delete" netbox.netbox.netbox_user_group: diff --git a/tests/integration/targets/v4.1/tasks/netbox_user_group.yml b/tests/integration/targets/v4.1/tasks/netbox_user_group.yml index 21a79ae19..0bedc95fb 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_user_group.yml @@ -91,7 +91,7 @@ ansible.builtin.assert: that: - test_five is changed - - test_five['user']['groups'] == [1] + - test_five['user']['groups'] == [test_one['user_group']['id']] - name: "USER_GROUP 6: Delete" netbox.netbox.netbox_user_group: diff --git a/tests/integration/targets/v4.2/tasks/netbox_user_group.yml b/tests/integration/targets/v4.2/tasks/netbox_user_group.yml index 21a79ae19..0bedc95fb 100644 --- a/tests/integration/targets/v4.2/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.2/tasks/netbox_user_group.yml @@ -91,7 +91,7 @@ ansible.builtin.assert: that: - test_five is changed - - test_five['user']['groups'] == [1] + - test_five['user']['groups'] == [test_one['user_group']['id']] - name: "USER_GROUP 6: Delete" netbox.netbox.netbox_user_group: diff --git a/tests/integration/targets/v4.3/tasks/netbox_user_group.yml b/tests/integration/targets/v4.3/tasks/netbox_user_group.yml index 21a79ae19..0bedc95fb 100644 --- a/tests/integration/targets/v4.3/tasks/netbox_user_group.yml +++ b/tests/integration/targets/v4.3/tasks/netbox_user_group.yml @@ -91,7 +91,7 @@ ansible.builtin.assert: that: - test_five is changed - - test_five['user']['groups'] == [1] + - test_five['user']['groups'] == [test_one['user_group']['id']] - name: "USER_GROUP 6: Delete" netbox.netbox.netbox_user_group: From d46f660b317ac91e3176f3e7696ab82630854bfb Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Sat, 23 Aug 2025 20:23:07 -0400 Subject: [PATCH 09/10] Use explicit ID in permission tests --- tests/integration/targets/v4.0/tasks/netbox_permission.yml | 4 ++-- tests/integration/targets/v4.1/tasks/netbox_permission.yml | 4 ++-- tests/integration/targets/v4.2/tasks/netbox_permission.yml | 4 ++-- tests/integration/targets/v4.3/tasks/netbox_permission.yml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/integration/targets/v4.0/tasks/netbox_permission.yml b/tests/integration/targets/v4.0/tasks/netbox_permission.yml index 86d6a02bb..9e46dd1ef 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_permission.yml @@ -115,7 +115,7 @@ ansible.builtin.assert: that: - test_five is changed - - test_five['user_group']['permissions'] == [1] + - test_five['user_group']['permissions'] == [test_one['permission']['id']] - name: "PERMISSION 6: Add permission to user" netbox.netbox.netbox_user: @@ -133,7 +133,7 @@ ansible.builtin.assert: that: - test_six is changed - - test_six['user']['permissions'] == [2] + - test_six['user']['permissions'] == [test_four['permission']['id']] - name: "PERMISSION 7: Delete" netbox.netbox.netbox_permission: diff --git a/tests/integration/targets/v4.1/tasks/netbox_permission.yml b/tests/integration/targets/v4.1/tasks/netbox_permission.yml index 86d6a02bb..9e46dd1ef 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_permission.yml @@ -115,7 +115,7 @@ ansible.builtin.assert: that: - test_five is changed - - test_five['user_group']['permissions'] == [1] + - test_five['user_group']['permissions'] == [test_one['permission']['id']] - name: "PERMISSION 6: Add permission to user" netbox.netbox.netbox_user: @@ -133,7 +133,7 @@ ansible.builtin.assert: that: - test_six is changed - - test_six['user']['permissions'] == [2] + - test_six['user']['permissions'] == [test_four['permission']['id']] - name: "PERMISSION 7: Delete" netbox.netbox.netbox_permission: diff --git a/tests/integration/targets/v4.2/tasks/netbox_permission.yml b/tests/integration/targets/v4.2/tasks/netbox_permission.yml index 86d6a02bb..9e46dd1ef 100644 --- a/tests/integration/targets/v4.2/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.2/tasks/netbox_permission.yml @@ -115,7 +115,7 @@ ansible.builtin.assert: that: - test_five is changed - - test_five['user_group']['permissions'] == [1] + - test_five['user_group']['permissions'] == [test_one['permission']['id']] - name: "PERMISSION 6: Add permission to user" netbox.netbox.netbox_user: @@ -133,7 +133,7 @@ ansible.builtin.assert: that: - test_six is changed - - test_six['user']['permissions'] == [2] + - test_six['user']['permissions'] == [test_four['permission']['id']] - name: "PERMISSION 7: Delete" netbox.netbox.netbox_permission: diff --git a/tests/integration/targets/v4.3/tasks/netbox_permission.yml b/tests/integration/targets/v4.3/tasks/netbox_permission.yml index 86d6a02bb..9e46dd1ef 100644 --- a/tests/integration/targets/v4.3/tasks/netbox_permission.yml +++ b/tests/integration/targets/v4.3/tasks/netbox_permission.yml @@ -115,7 +115,7 @@ ansible.builtin.assert: that: - test_five is changed - - test_five['user_group']['permissions'] == [1] + - test_five['user_group']['permissions'] == [test_one['permission']['id']] - name: "PERMISSION 6: Add permission to user" netbox.netbox.netbox_user: @@ -133,7 +133,7 @@ ansible.builtin.assert: that: - test_six is changed - - test_six['user']['permissions'] == [2] + - test_six['user']['permissions'] == [test_four['permission']['id']] - name: "PERMISSION 7: Delete" netbox.netbox.netbox_permission: From 0b8c44266c38ad4b318ed5f181eeb7ee1be89332 Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Sat, 23 Aug 2025 20:25:08 -0400 Subject: [PATCH 10/10] Use explicit ID in token tests --- tests/integration/targets/v4.0/tasks/netbox_token.yml | 3 ++- tests/integration/targets/v4.1/tasks/netbox_token.yml | 3 ++- tests/integration/targets/v4.2/tasks/netbox_token.yml | 3 ++- tests/integration/targets/v4.3/tasks/netbox_token.yml | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/integration/targets/v4.0/tasks/netbox_token.yml b/tests/integration/targets/v4.0/tasks/netbox_token.yml index 63524494a..abfe53e79 100644 --- a/tests/integration/targets/v4.0/tasks/netbox_token.yml +++ b/tests/integration/targets/v4.0/tasks/netbox_token.yml @@ -12,6 +12,7 @@ username: TestUser password: TestPassword1 state: present + register: test_user - name: "TOKEN 1: Necessary info creation" netbox.netbox.netbox_token: @@ -29,7 +30,7 @@ - test_one is changed - test_one['diff']['before']['state'] == "absent" - test_one['diff']['after']['state'] == "present" - - test_one['token']['user'] == 3 + - test_one['token']['user'] == test_user['user']['id'] - test_one['msg'] == "token ******** created" - name: "TOKEN 2: Create duplicate" diff --git a/tests/integration/targets/v4.1/tasks/netbox_token.yml b/tests/integration/targets/v4.1/tasks/netbox_token.yml index a602883fe..e8b2aa165 100644 --- a/tests/integration/targets/v4.1/tasks/netbox_token.yml +++ b/tests/integration/targets/v4.1/tasks/netbox_token.yml @@ -12,6 +12,7 @@ username: TestUser password: TestPassword2 state: present + register: test_user - name: "TOKEN 1: Necessary info creation" netbox.netbox.netbox_token: @@ -29,7 +30,7 @@ - test_one is changed - test_one['diff']['before']['state'] == "absent" - test_one['diff']['after']['state'] == "present" - - test_one['token']['user'] == 3 + - test_one['token']['user'] == test_user['user']['id'] - test_one['msg'] == "token ******** created" - name: "TOKEN 2: Create duplicate" diff --git a/tests/integration/targets/v4.2/tasks/netbox_token.yml b/tests/integration/targets/v4.2/tasks/netbox_token.yml index a602883fe..e8b2aa165 100644 --- a/tests/integration/targets/v4.2/tasks/netbox_token.yml +++ b/tests/integration/targets/v4.2/tasks/netbox_token.yml @@ -12,6 +12,7 @@ username: TestUser password: TestPassword2 state: present + register: test_user - name: "TOKEN 1: Necessary info creation" netbox.netbox.netbox_token: @@ -29,7 +30,7 @@ - test_one is changed - test_one['diff']['before']['state'] == "absent" - test_one['diff']['after']['state'] == "present" - - test_one['token']['user'] == 3 + - test_one['token']['user'] == test_user['user']['id'] - test_one['msg'] == "token ******** created" - name: "TOKEN 2: Create duplicate" diff --git a/tests/integration/targets/v4.3/tasks/netbox_token.yml b/tests/integration/targets/v4.3/tasks/netbox_token.yml index a602883fe..e8b2aa165 100644 --- a/tests/integration/targets/v4.3/tasks/netbox_token.yml +++ b/tests/integration/targets/v4.3/tasks/netbox_token.yml @@ -12,6 +12,7 @@ username: TestUser password: TestPassword2 state: present + register: test_user - name: "TOKEN 1: Necessary info creation" netbox.netbox.netbox_token: @@ -29,7 +30,7 @@ - test_one is changed - test_one['diff']['before']['state'] == "absent" - test_one['diff']['after']['state'] == "present" - - test_one['token']['user'] == 3 + - test_one['token']['user'] == test_user['user']['id'] - test_one['msg'] == "token ******** created" - name: "TOKEN 2: Create duplicate"