From bc6e8e5874f85ebda9bd02a43955c6c45aaf30a9 Mon Sep 17 00:00:00 2001 From: Rickmarges Date: Wed, 1 Nov 2023 04:45:11 +0100 Subject: [PATCH] Change order of operations (#719) Add new/updated key to dict only after removing old ones Co-authored-by: Marges, RSY (Rick) Co-authored-by: Sean Sullivan --- plugins/lookup/controller_object_diff.py | 2 +- roles/object_diff/tasks/roles.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/lookup/controller_object_diff.py b/plugins/lookup/controller_object_diff.py index 47b5821a8..b9eeaaf08 100644 --- a/plugins/lookup/controller_object_diff.py +++ b/plugins/lookup/controller_object_diff.py @@ -115,9 +115,9 @@ def create_present_list(self, compare_list): def map_item(self, item, new_attribute_name, attribute_value, dupitems): new_item = copy.deepcopy(item) - new_item.update({new_attribute_name: attribute_value}) for dupitem in [dupitem for dupitem in dupitems if dupitem in new_item]: new_item.pop(dupitem) + new_item.update({new_attribute_name: attribute_value}) return new_item def run(self, terms, variables=None, **kwargs): diff --git a/roles/object_diff/tasks/roles.yml b/roles/object_diff/tasks/roles.yml index 82572428f..f284ccbfa 100644 --- a/roles/object_diff/tasks/roles.yml +++ b/roles/object_diff/tasks/roles.yml @@ -11,7 +11,7 @@ - __controller_api_current_user_check_is_admin.is_superuser block: - - name: "Get the API list of all roles" # noqa jinja[spacing] + - name: "Get the API list of all roles" ansible.builtin.set_fact: __controller_api_roles: "{{ (__controller_api_roles | default([])) + [{ 'users': current_users, @@ -19,8 +19,8 @@ 'name': current_role.name, 'role': current_role.name, 'type': current_role.type, - 'resource_type': (current_role.summary_fields.resource_type|default('no_resource_type')), - (current_role.summary_fields.resource_type|default('no_resource_type')): (current_role.summary_fields.resource_name|default('no_resource_name')) + 'resource_type': (current_role.summary_fields.resource_type | default('no_resource_type')), + (current_role.summary_fields.resource_type | default('no_resource_type')): (current_role.summary_fields.resource_name | default('no_resource_name')) }] }}" vars: