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

Can't create folder #145

Closed
nlamirault opened this issue Jan 26, 2021 · 11 comments
Closed

Can't create folder #145

nlamirault opened this issue Jan 26, 2021 · 11 comments

Comments

@nlamirault
Copy link

SUMMARY

I try to create a folder and upload a dashboard

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_folder

ANSIBLE VERSION
❯ ansible --version
ansible 2.10.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/nicolas/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.9.1 (default, Dec 13 2020, 11:55:53) [GCC 10.2.0]
CONFIGURATION

OS / ENVIRONMENT

Linux
Grafana 7.0

STEPS TO REPRODUCE
grafana_url: https://grafana.xxxxxxx.com
grafana_api_key: xxxxxxxxxxxx
grafana_dashboard_path: files/dashboards/
- name: Create a folder
  community.grafana.grafana_folder:
    url: "{{ grafana_url }}"
    grafana_api_key: "{{ grafana_api_key }}"
    title: "commons"
    state: present

- name: Import Grafana dashboard Sk5/Commons
  community.grafana.grafana_dashboard:
    grafana_url: "{{ grafana_url }}"
    grafana_api_key: "{{ grafana_api_key }}"
    state: present
    commit_message: Updated by ansible
    overwrite: yes
    folder: commons
    path: "{{ grafana_dashboard_path }}/sk5-mixin/k8sclusteroverview.json"
EXPECTED RESULTS
  • A folder "commons" created
  • A dashboard uploaded
ACTUAL RESULTS

An error on folder creation :

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost] ***************************************************************************************************************************************************************************************************

TASK [minotor : Create a folder] ***********************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: invalid literal for int() with base 10: '0-beta3'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/nicolas/.ansible/tmp/ansible-tmp-1611602773.6373312-1482350-251097151758827/AnsiballZ_grafana_folder.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/nicolas/.ansible/tmp/ansible-tmp-1611602773.6373312-1482350-251097151758827/AnsiballZ_grafana_folder.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/nicolas/.ansible/tmp/ansible-tmp-1611602773.6373312-1482350-251097151758827/AnsiballZ_grafana_folder.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.grafana.plugins.modules.grafana_folder', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_2gl7pvlh/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 274, in <module>\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_2gl7pvlh/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 254, in main\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_2gl7pvlh/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 178, in __init__\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_2gl7pvlh/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 209, in get_version\nValueError: invalid literal for int() with base 10: '0-beta3'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

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

Upload dashboard without specify folder works fine :

- name: Import Grafana dashboard Sk5/Commons
  community.grafana.grafana_dashboard:
    grafana_url: "{{ grafana_url }}"
    grafana_api_key: "{{ grafana_api_key }}"
    state: present
    commit_message: Updated by ansible
    overwrite: yes
    # folder: sk5-commons
    path: "{{ grafana_dashboard_path }}/sk5-mixin/k8sclusteroverview.json"
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost] ***************************************************************************************************************************************************************************************************

TASK [minotor : Import Grafana dashboard Sk5/Commons] **************************************************************************************************************************************************************
changed: [localhost]

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

An dashboard is on Grafana.

Trying to upload dashboard to a non-existent folder, I've got no error but in debug i see an incorrect response:

- name: Import Grafana dashboard Sk5/Commons
  community.grafana.grafana_dashboard:
    grafana_url: "{{ grafana_url }}"
    grafana_api_key: "{{ grafana_api_key }}"
    state: present
    commit_message: Updated by ansible
    overwrite: yes
    folder: commons
    path: "{{ grafana_dashboard_path }}/sk5-mixin/k8sclusteroverview.json"
TASK [minotor : Import Grafana dashboard Sk5/Commons] **************************************************************************************************************************************************************
task path: /home/nicolas/Work/skale-5/minotor-mixins/minotor/ansible/roles/minotor/tasks/grafana.yml:16
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: nicolas
<127.0.0.1> EXEC /bin/sh -c 'echo ~nicolas && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/nicolas/.ansible/tmp `"&& mkdir "` echo /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939 `" && echo ansible-tmp-1611644323.457462-1501296-28685885933939="` echo /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939 `" ) && sleep 0'
Using module file /home/nicolas/Work/skale-5/minotor-mixins/venv/lib/python3.9/site-packages/ansible_collections/community/grafana/plugins/modules/grafana_dashboard.py
<127.0.0.1> PUT /home/nicolas/.ansible/tmp/ansible-local-150129282072vpi/tmpuk2rhce3 TO /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939/AnsiballZ_grafana_dashboard.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939/ /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939/AnsiballZ_grafana_dashboard.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S -n  -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-vrznksyuvpcacajbzlribdphxekycfzt ; /home/nicolas/Work/skale-5/minotor-mixins/venv/bin/python3 /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939/AnsiballZ_grafana_dashboard.py'"'"' && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "client_cert": null,
            "client_key": null,
            "commit_message": "Updated by ansible",
            "dashboard_id": null,
            "dashboard_revision": "1",
            "folder": "commons",
            "grafana_api_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "grafana_url": "https://grafana.xxxxxxxxxxxx.com",
            "org_id": 1,
            "overwrite": true,
            "path": "files/dashboards//sk5-mixin/k8sclusteroverview.json",
            "slug": null,
            "state": "present",
            "uid": null,
            "url": "https://grafana.xxxxxxxxx.com",
            "url_password": "admin",
            "url_username": "admin",
            "use_proxy": true,
            "validate_certs": true
        }
    },
    "msg": "Dashboard folder 'commons' does not exist.",
    "uid": "72b917dce60538f3282c1c4ed7c277d8"
}
Read vars_file './env_vars/{{ env }}/minotor.yml'
META: ran handlers
Read vars_file './env_vars/{{ env }}/minotor.yml'
META: ran handlers

PLAY RECAP *********************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
@rrey
Copy link
Collaborator

rrey commented Jan 26, 2021

Is your Grafana version 7.X.x-beta3 ?

@nlamirault
Copy link
Author

Yes 7.0.0-beta3 @rrey

@rrey
Copy link
Collaborator

rrey commented Jan 26, 2021

The bug comes from the version parsing function in the collection that doesn’t support bêta mention. I won’t be able to fix that today so you’ll have to wait a bit.

aside from the bugfix, you could install the stable grafana release and have no problem 😉

@nlamirault
Copy link
Author

Ok. Thanks. I will deploy another Grafana version.

@nlamirault
Copy link
Author

It works fine on a stable version. Thanks

@gacallea
Copy link

gacallea commented Feb 3, 2021

I'm having the same issue on the latest stable Grafana installed from their repository on Ubuntu 20.04:

ansible --version
ansible 2.10.5
  config file = /Users/xxx/yada/yada/ansible.cfg
  configured module search path = ['/Users/xxxxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.1 (default, Jan 30 2021, 15:51:59) [Clang 12.0.0 (clang-1200.0.32.29)]
grafana-cli --version
Grafana CLI version 7.3.7

grafana-server -v
Version 7.3.7 (commit: 1e261642f4, branch: HEAD)
- name: "Create {{ pool_ticker }} folder"
  community.grafana.grafana_folder:
    state: present
    name: "{{ pool_ticker }}"
    url: "https://{{ grafana_domain }}"
    url_username: "{{ grafana_admin_user }}"
    url_password: "{{ grafana_admin_pass }}"
- name: "Import {{ pool_ticker }} Metrics v1 Dashboard"
  community.grafana.grafana_dashboard:
    dashboard_revision: "1"
    folder: "{{ pool_ticker }}"
    path: "/tmp/{{ pool_ticker }}-PoolMetricsV1.json"
    grafana_url: "https://{{ grafana_domain }}"
    url_username: "{{ grafana_admin_user }}"
    url_password: "{{ grafana_admin_pass }}"

@rrey
Copy link
Collaborator

rrey commented Feb 3, 2021

@gacallea please post your error message

@gacallea
Copy link

gacallea commented Feb 4, 2021

@gacallea please post your error message

I hope this helps.

fatal: [spaas-mon]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 142.93.43.238 closed.\r\n", "module_stdout": "\r\nTraceback (most recent call last):\r\n  File \"/home/igghibu/.ansible/tmp/ansible-tmp-1612433673.381998-67602-133808153941091/AnsiballZ_grafana_folder.py\", line 102, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/igghibu/.ansible/tmp/ansible-tmp-1612433673.381998-67602-133808153941091/AnsiballZ_grafana_folder.py\", line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/igghibu/.ansible/tmp/ansible-tmp-1612433673.381998-67602-133808153941091/AnsiballZ_grafana_folder.py\", line 40, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.community.grafana.plugins.modules.grafana_folder', init_globals=None, run_name='__main__', alter_sys=True)\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.grafana.grafana_folder_payload_ybp_mas9/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 274, in <module>\r\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_ybp_mas9/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 254, in main\r\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_ybp_mas9/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 178, in __init__\r\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_ybp_mas9/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 208, in get_version\r\nAttributeError: 'NoneType' object has no attribute 'split'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

ps: please let me know how to prettify the error message. I didn't expect one line.

@rrey
Copy link
Collaborator

rrey commented Feb 4, 2021

 line 208, in get_version\r\nAttributeError: 'NoneType' object has no attribute 'split'\r\n"

@gacallea Can you post the answer of your server on /api/health endpoint ?

Edit: please open a new issue so we don't spoil to much this closed one. thank you in advance

@gacallea
Copy link

gacallea commented Feb 4, 2021

ok :)

@gacallea
Copy link

gacallea commented Feb 4, 2021

 line 208, in get_version\r\nAttributeError: 'NoneType' object has no attribute 'split'\r\n"

@gacallea Can you post the answer of your server on /api/health endpoint ?

Edit: please open a new issue so we don't spoil to much this closed one. thank you in advance

here it is #147 :)

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

No branches or pull requests

3 participants