diff --git a/changelogs/fragments/2499-influxdb_user-fix-multiple-no-privileges.yml b/changelogs/fragments/2499-influxdb_user-fix-multiple-no-privileges.yml new file mode 100644 index 0000000000..d4575ea711 --- /dev/null +++ b/changelogs/fragments/2499-influxdb_user-fix-multiple-no-privileges.yml @@ -0,0 +1,2 @@ +bugfixes: + - influxdb_user - fix bug where an influxdb user has no privileges for 2 or more databases (https://github.com/ansible-collections/community.general/pull/2499). diff --git a/plugins/modules/database/influxdb/influxdb_user.py b/plugins/modules/database/influxdb/influxdb_user.py index e17e3753f2..8aec04533b 100644 --- a/plugins/modules/database/influxdb/influxdb_user.py +++ b/plugins/modules/database/influxdb/influxdb_user.py @@ -166,16 +166,16 @@ def set_user_grants(module, client, user_name, grants): try: current_grants = client.get_list_privileges(user_name) + parsed_grants = [] # Fix privileges wording for i, v in enumerate(current_grants): - if v['privilege'] == 'ALL PRIVILEGES': - v['privilege'] = 'ALL' - current_grants[i] = v - elif v['privilege'] == 'NO PRIVILEGES': - del(current_grants[i]) + if v['privilege'] != 'NO PRIVILEGES': + if v['privilege'] == 'ALL PRIVILEGES': + v['privilege'] = 'ALL' + parsed_grants.add(v) # check if the current grants are included in the desired ones - for current_grant in current_grants: + for current_grant in parsed_grants: if current_grant not in grants: if not module.check_mode: client.revoke_privilege(current_grant['privilege'], @@ -185,7 +185,7 @@ def set_user_grants(module, client, user_name, grants): # check if the desired grants are included in the current ones for grant in grants: - if grant not in current_grants: + if grant not in parsed_grants: if not module.check_mode: client.grant_privilege(grant['privilege'], grant['database'],