Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError 'NoneType' object has no attribute get - Module failure #333

Open
enidvx opened this issue Dec 2, 2023 · 7 comments · May be fixed by #359
Open

AttributeError 'NoneType' object has no attribute get - Module failure #333

enidvx opened this issue Dec 2, 2023 · 7 comments · May be fixed by #359

Comments

@enidvx
Copy link

enidvx commented Dec 2, 2023

Hello,
I am getting this error when trying to execute grafana_user module:

File \"master:/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 304, in <module>\n  File \"master:/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 286, in main\n  File \"master:/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 232, in is_user_update_required\nAttributeError: 'NoneType' object has no attribute 'get'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

I am using:

community.grafana 1.6.1
grafana version 10.2.1
ansible==8.3.0
ansible-core==2.15.3

I cannot execute this task at all:

  community.grafana.grafana_user:
    url: "https://{{ ansible_fqdn }}"
    url_username: "{{ grafana_admin_user }}"
    url_password: "{{ grafana_admin_password }}"
    login: "{{ member.uid }}"
    email: "{{ member.email }}"
    name: "{{ member.description }}"
    password: "{{ member.password }}"
    state: "present"

Is there anything I can do to solve the issue?
Thanks

@Nemental
Copy link
Collaborator

Nemental commented Dec 4, 2023

Hi @enidvx
Can you please provide your members variable (anonymized)?
Do you know which user/item of the list is affected?
As I understand it, the problem is that the target user doesn't have an email address. But how is that possible? :D

@enidvx
Copy link
Author

enidvx commented Dec 5, 2023

Hi @Nemental
These are some of the vars that are used to loop on users list:

'uid': 'username', 
'description': 'User Name', 
'email': 'user.name@whatever.com', 
'password': 'hashed_passwd'

From all the config all vars seem to be fine because this used to work on another older instance of grafana and community.grafana.

@Nemental
Copy link
Collaborator

Nemental commented Dec 5, 2023

Hey @enidvx
I'm sorry but I can't recreate this... I tried several things, even edited the Grafana database manually but without success.

@enidvx
Copy link
Author

enidvx commented Dec 8, 2023

I even tested it with grafana version 10.2.0 which according to the community.grafana Readme is the last supported version and I do get the exact same error:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'get'
fatal: [grafana-1.domain.io]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 107, in <module>\n  File \"<stdin>\", line 99, in _ansiballz_main\n  File \"<stdin>\", line 47, in invoke_module\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_ed5er12q/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 304, in <module>\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_ed5er12q/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 286, in main\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_ed5er12q/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 232, in is_user_update_required\nAttributeError: 'NoneType' object has no attribute 'get'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

I even tested with and without mitogen enabled (strategy: linear, and strategy: mitogen_linear)
with the same error 😞

@Demisu
Copy link

Demisu commented Mar 4, 2024

Hello,

I have the same issue when creating or updating new users.
I have a fresh install of grafana 9.2.20, but I'm using the PMM version and I don't know if it is related.

Ansible 9.3.0
Ansible-core 2.16.4
community.grafana 1.8.0

@enidvx
Copy link
Author

enidvx commented Apr 24, 2024

I tried again with the latest versions and also a fresh install in hope to have some fix but unfortunately again the same output:

community.grafana 1.8.0
grafana version 10.2.2
ansible==8.6.0
ansible-core==2.15.6

still error is:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'get' fatal: [grafana-1.host.domain]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"<stdin>\", line 107, in <module>\n File \"<stdin>\", line 99, in _ansiballz_main\n File \"<stdin>\", line 47, in invoke_module\n File \"<frozen runpy>\", line 226, in run_module\n File \"<frozen runpy>\", line 98, in _run_module_code\n File \"<frozen runpy>\", line 88, in _run_code\n File \"/tmp/ansible_community.grafana.grafana_user_payload_rj6zf5tf/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 323, in <module>\n File \"/tmp/ansible_community.grafana.grafana_user_payload_rj6zf5tf/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 303, in main\n File \"/tmp/ansible_community.grafana.grafana_user_payload_rj6zf5tf/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 247, in is_user_update_required\nAttributeError: 'NoneType' object has no attribute 'get'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

@rndmh3ro
Copy link
Collaborator

rndmh3ro commented Apr 24, 2024

I can reproduce a similar bug:

  1. run grafana
> docker run -d -p 3000:3000 grafana/grafana:10.2.2
  1. run the following playbook:
---
- hosts: localhost
  gather_facts: no
  vars:
    grafana_admin_user: grafana
    grafana_admin_password: grafana
    members:
      - uid: username
        description: 'User Name'
        email: 'user.name@whatever.com'
        password: 'hashed_passwd'
      - uid: username2
        description: 'User Name1'
        email: 'user.name2@whatever.com'
        password: 'hashed_passwd'
  tasks:
    - name: Create Grafana users
      community.grafana.grafana_user:
        url: "https://127.0.0.1"        # ## notice this is wrong
        url_username: "{{ grafana_admin_user }}"
        url_password: "{{ grafana_admin_password }}"
        login: "{{ member.uid }}"
        email: "{{ member.email }}"
        name: "{{ member.description }}"
        password: "{{ member.password }}"
        state: "present"
      loop: "{{ members }}"
      loop_control:
        loop_var: member

result:

> ansible-playbook test2.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
 __________________
< PLAY [localhost] >
 ------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

 _____________________________
< TASK [Create Grafana users] >
 -----------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'read'
failed: [localhost] (item={'uid': 'username', 'description': 'User Name', 'email': 'user.name@whatever.com', 'password': 'hashed_passwd'}) => {"ansible_loop_var": "member", "changed": false, "member": {"description": "User Name", "email": "user.name@whatever.com", "password": "hashed_passwd", "uid": "username"}, "module_stderr": "Traceback (most recent call last):\n  File \"/home/segu/.ansible/tmp/ansible-tmp-1713969893.8799918-1346142-270361372579429/AnsiballZ_grafana_user.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/segu/.ansible/tmp/ansible-tmp-1713969893.8799918-1346142-270361372579429/AnsiballZ_grafana_user.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/segu/.ansible/tmp/ansible-tmp-1713969893.8799918-1346142-270361372579429/AnsiballZ_grafana_user.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.grafana.plugins.modules.grafana_user', init_globals=dict(_module_fqn='ansible_collections.community.grafana.plugins.modules.grafana_user', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_ctp3n329/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 323, in <module>\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_ctp3n329/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 292, in main\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_ctp3n329/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 221, in get_user_from_login\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_ctp3n329/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 204, in _send_request\nAttributeError: 'NoneType' object has no attribute 'read'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'read'
failed: [localhost] (item={'uid': 'username2', 'description': 'User Name1', 'email': 'user.name2@whatever.com', 'password': 'hashed_passwd'}) => {"ansible_loop_var": "member", "changed": false, "member": {"description": "User Name1", "email": "user.name2@whatever.com", "password": "hashed_passwd", "uid": "username2"}, "module_stderr": "Traceback (most recent call last):\n  File \"/home/segu/.ansible/tmp/ansible-tmp-1713969894.262415-1346142-167829676315139/AnsiballZ_grafana_user.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/segu/.ansible/tmp/ansible-tmp-1713969894.262415-1346142-167829676315139/AnsiballZ_grafana_user.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/segu/.ansible/tmp/ansible-tmp-1713969894.262415-1346142-167829676315139/AnsiballZ_grafana_user.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.grafana.plugins.modules.grafana_user', init_globals=dict(_module_fqn='ansible_collections.community.grafana.plugins.modules.grafana_user', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_vtib7xty/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 323, in <module>\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_vtib7xty/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 292, in main\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_vtib7xty/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 221, in get_user_from_login\n  File \"/tmp/ansible_community.grafana.grafana_user_payload_vtib7xty/ansible_community.grafana.grafana_user_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_user.py\", line 204, in _send_request\nAttributeError: 'NoneType' object has no attribute 'read'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
 ____________
< PLAY RECAP >
 ------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

@rndmh3ro rndmh3ro linked a pull request Apr 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants