From 3fb1ff0b720eb28ea7014597ce4defb79956b597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Tich=C3=BD?= Date: Wed, 22 Mar 2023 07:38:31 +0100 Subject: [PATCH] Fix influxdb_user grants in check mode (#6111) * Fix influxdb_user grants in check mode When running in check mode, `influxdb_user` will return error when the user doesn't exist yet, instead of reporting `changed` state. * Update changelogs/fragments/6111-influxdb_user-check-mode.yaml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- changelogs/fragments/6111-influxdb_user-check-mode.yaml | 2 ++ plugins/modules/influxdb_user.py | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 changelogs/fragments/6111-influxdb_user-check-mode.yaml 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/influxdb_user.py b/plugins/modules/influxdb_user.py index e893fc0759..bbd0f8f5ab 100644 --- a/plugins/modules/influxdb_user.py +++ b/plugins/modules/influxdb_user.py @@ -174,8 +174,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):