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
This commit is contained in:
Eike Frost 2019-01-23 09:53:07 +01:00 committed by ansibot
parent 87a01df6ad
commit 3c39c5d456

View file

@ -741,13 +741,20 @@ def main():
changeset = dict() changeset = dict()
for client_param in client_params: for client_param in client_params:
# lists in the Keycloak API are sorted
new_param_value = module.params.get(client_param) 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): if isinstance(new_param_value, list):
try: if client_param in ['attributes']:
new_param_value = sorted(new_param_value) try:
except TypeError: new_param_value = sorted(new_param_value)
pass 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 changeset[camel(client_param)] = new_param_value
# Whether creating or updating a client, take the before-state and merge the changeset into it # Whether creating or updating a client, take the before-state and merge the changeset into it