Repository: ansible-collections/community.general

Issue:
community.general.influxdb_user error since "Update influxdb_user.py Fixed Multiple No Privileges #2499"
### Summary

Currently have the following task defined to create a DB user:

- name: InfluxDB - Create a telegraf user on localhost with privileges
  community.general.influxdb_user:
    user_name: "{{ telegraf_influxdb_username }}"
    user_password: "{{ telegraf_influxdb_password }}"
    login_username: "{{ influxdb_admin_username }}"
    login_password: "{{ influxdb_admin_password }}"
    grants:
      - database: "{{telegraf_influxdb_database_name}}"
        privilege: 'ALL'

Prior to #2499 this task worked with no issues, now errors with the following:

TASK [docker_tighost : InfluxDB - Create a telegraf user on localhost with privileges] *************
fatal: [bailey]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.15.5 closed.\r\n", "module_stdout": "\r\nTraceback (most recent call last):\r\n  File \"/home/psf/.ansible/tmp/ansible-tmp-1621930443.762264-4349-19899814552164/AnsiballZ_influxdb_user.py\", line 100, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/psf/.ansible/tmp/ansible-tmp-1621930443.762264-4349-19899814552164/AnsiballZ_influxdb_user.py\", line 92, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/psf/.ansible/tmp/ansible-tmp-1621930443.762264-4349-19899814552164/AnsiballZ_influxdb_user.py\", line 40, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.influxdb_user', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.influxdb_user', _modlib_path=modlib_path),\r\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_community.general.influxdb_user_payload_ul53ub5s/ansible_community.general.influxdb_user_payload.zip/ansible_collections/community/general/plugins/modules/influxdb_user.py\", line 284, in <module>\r\n  File \"/tmp/ansible_community.general.influxdb_user_payload_ul53ub5s/ansible_community.general.influxdb_user_payload.zip/ansible_collections/community/general/plugins/modules/influxdb_user.py\", line 271, in main\r\n  File \"/tmp/ansible_community.general.influxdb_user_payload_ul53ub5s/ansible_community.general.influxdb_user_payload.zip/ansible_collections/community/general/plugins/modules/influxdb_user.py\", line 177, in set_user_grants\r\nAttributeError: 'list' object has no attribute 'add'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Line 177 reflects s change made in #2499 to the parsing of existing privileges.

### Issue Type

Bug Report

### Component Name

community.general.influxdb_user
influxdb_user.py

### Ansible Version

```console (paste below)
psf@fastnet:ansible % ansible --version                                                     (mainU)
ansible [core 2.11.1] 
  config file = None
  configured module search path = ['/Users/psf/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/psf/.ansible/collections:/usr/share/ansible/collections
  executable location = /Library/Frameworks/Python.framework/Versions/3.9/bin/ansible
  python version = 3.9.4 (v3.9.4:1f2e3088f3, Apr  4 2021, 12:32:44) [Clang 6.0 (clang-600.0.57)]
  jinja version = 3.0.1
  libyaml = False

```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed

```
Empty

### OS / Environment

MacOS Catalina

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)

- name: InfluxDB - Create a telegraf user on localhost with privileges
  community.general.influxdb_user:
    user_name: "{{ telegraf_influxdb_username }}"
    user_password: "{{ telegraf_influxdb_password }}"
    login_username: "{{ influxdb_admin_username }}"
    login_password: "{{ influxdb_admin_password }}"
    grants:
      - database: "{{telegraf_influxdb_database_name}}"
        privilege: 'ALL'

```


### Expected Results

Expected task to skip user creation if created, or create user if not exist.

### Actual Results

```console (paste below)
TASK [docker_tighost : InfluxDB - Create a telegraf user on localhost with privileges] *************
fatal: [bailey]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.15.5 closed.\r\n", "module_stdout": "\r\nTraceback (most recent call last):\r\n  File \"/home/psf/.ansible/tmp/ansible-tmp-1621930443.762264-4349-19899814552164/AnsiballZ_influxdb_user.py\", line 100, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/psf/.ansible/tmp/ansible-tmp-1621930443.762264-4349-19899814552164/AnsiballZ_influxdb_user.py\", line 92, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/psf/.ansible/tmp/ansible-tmp-1621930443.762264-4349-19899814552164/AnsiballZ_influxdb_user.py\", line 40, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.influxdb_user', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.influxdb_user', _modlib_path=modlib_path),\r\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_community.general.influxdb_user_payload_ul53ub5s/ansible_community.general.influxdb_user_payload.zip/ansible_collections/community/general/plugins/modules/influxdb_user.py\", line 284, in <module>\r\n  File \"/tmp/ansible_community.general.influxdb_user_payload_ul53ub5s/ansible_community.general.influxdb_user_payload.zip/ansible_collections/community/general/plugins/modules/influxdb_user.py\", line 271, in main\r\n  File \"/tmp/ansible_community.general.influxdb_user_payload_ul53ub5s/ansible_community.general.influxdb_user_payload.zip/ansible_collections/community/general/plugins/modules/influxdb_user.py\", line 177, in set_user_grants\r\nAttributeError: 'list' object has no attribute 'add'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/database/influxdb/influxdb_user.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/database/influxdb/influxdb_user.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @kamsz @zhhuta
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
CC @sgalea87
Apologies, fixed in https://github.com/ansible-collections/community.general/pull/2614 @felixfontein 

Resolving patch:
diff --git a/plugins/modules/database/influxdb/influxdb_user.py b/plugins/modules/database/influxdb/influxdb_user.py
--- a/plugins/modules/database/influxdb/influxdb_user.py
+++ b/plugins/modules/database/influxdb/influxdb_user.py
@@ -174,7 +174,7 @@ def set_user_grants(module, client, user_name, grants):
             if v['privilege'] != 'NO PRIVILEGES':
                 if v['privilege'] == 'ALL PRIVILEGES':
                     v['privilege'] = 'ALL'
-                parsed_grants.add(v)
+                parsed_grants.append(v)
 
         # check if the current grants are included in the desired ones
         for current_grant in parsed_grants:


Test patch: