From 3c39c5d45637f7f808734356cb775566e181743e Mon Sep 17 00:00:00 2001 From: Eike Frost Date: Wed, 23 Jan 2019 09:53:07 +0100 Subject: [PATCH] keycloak_client: fix ansible diff/changed (sorting, null-values) (#39515) * - Fix sorting bug related to diff (attributes is sorted in the API, other lists are not) - Remove null-valued entries from protocolMappers introduced by Ansible's argument spec checking (also fixes diff output). * python2.6-ified dict comprehension * avoid use of map --- .../identity/keycloak/keycloak_client.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/identity/keycloak/keycloak_client.py b/lib/ansible/modules/identity/keycloak/keycloak_client.py index 425304ca8df..2e040e6d250 100644 --- a/lib/ansible/modules/identity/keycloak/keycloak_client.py +++ b/lib/ansible/modules/identity/keycloak/keycloak_client.py @@ -741,13 +741,20 @@ def main(): changeset = dict() for client_param in client_params: - # lists in the Keycloak API are sorted new_param_value = module.params.get(client_param) + + # some lists in the Keycloak API are sorted, some are not. if isinstance(new_param_value, list): - try: - new_param_value = sorted(new_param_value) - except TypeError: - pass + if client_param in ['attributes']: + try: + new_param_value = sorted(new_param_value) + except TypeError: + pass + # Unfortunately, the ansible argument spec checker introduces variables with null values when + # they are not specified + if client_param == 'protocol_mappers': + new_param_value = [dict((k, v) for k, v in x.items() if x[k] is not None) for x in new_param_value] + changeset[camel(client_param)] = new_param_value # Whether creating or updating a client, take the before-state and merge the changeset into it