diff --git a/changelogs/fragments/6111-influxdb_user-check-mode.yaml b/changelogs/fragments/6111-influxdb_user-check-mode.yaml new file mode 100644 index 0000000000..4789c2ba76 --- /dev/null +++ b/changelogs/fragments/6111-influxdb_user-check-mode.yaml @@ -0,0 +1,2 @@ +bugfixes: + - influxdb_user - fix running in check mode when the user does not exist yet (https://github.com/ansible-collections/community.general/pull/6111). diff --git a/plugins/modules/database/influxdb/influxdb_user.py b/plugins/modules/database/influxdb/influxdb_user.py index 25bc2a95ce..b66c89401e 100644 --- a/plugins/modules/database/influxdb/influxdb_user.py +++ b/plugins/modules/database/influxdb/influxdb_user.py @@ -168,8 +168,14 @@ def drop_user(module, client, user_name): def set_user_grants(module, client, user_name, grants): changed = False + current_grants = [] try: current_grants = client.get_list_privileges(user_name) + except influx.exceptions.InfluxDBClientError as e: + if not module.check_mode or 'user not found' not in e.content: + module.fail_json(msg=e.content) + + try: parsed_grants = [] # Fix privileges wording for i, v in enumerate(current_grants):