From e0465d1f48d5277d693d7ea2f46504fad152b859 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 22 Mar 2023 13:16:21 +0100 Subject: [PATCH] [PR #6111/3fb1ff0b backport][stable-6] Fix influxdb_user grants in check mode (#6214) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit 3fb1ff0b720eb28ea7014597ce4defb79956b597) Co-authored-by: Petr Tichý --- 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 00000000000..4789c2ba76d --- /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 e893fc07592..bbd0f8f5ab3 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):