Skip to content

Commit

Permalink
[PR #6111/3fb1ff0b backport][stable-6] Fix influxdb_user grants in ch…
Browse files Browse the repository at this point in the history
…eck mode (#6214)

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 <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 3fb1ff0)

Co-authored-by: Petr Tichý <petr@pex.com>
  • Loading branch information
patchback[bot] and Petr Tichý authored Mar 22, 2023
1 parent ad6c280 commit e0465d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6111-influxdb_user-check-mode.yaml
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 6 additions & 0 deletions plugins/modules/influxdb_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e0465d1

Please sign in to comment.