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 on Grafana 7.3.7 stable (tried 7.1.3 as well, same issue) #147

Closed
gacallea opened this issue Feb 4, 2021 · 15 comments
Closed
Milestone

Comments

@gacallea
Copy link

gacallea commented Feb 4, 2021

SUMMARY

Trying to create "named folders" and upload "named dashboards" to them.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.grafana.grafana_folder

ANSIBLE VERSION
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)]
CONFIGURATION

OS / ENVIRONMENT

Ubuntu 20.04
Grafana 7.3.7 stable -- installed from the official Grafana repository (oss stable)

STEPS TO REPRODUCE

Posting the relevant tasks only. All variables work in other tasks. The upload to /tmp/dashboard is omitted here.

- 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 }}"
EXPECTED RESULTS

a folder with a ticker name should be created.
a ticker named dashboard should be uploaded to the above folder.

ACTUAL RESULTS
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}
@rrey
Copy link
Collaborator

rrey commented Feb 7, 2021

Tested locally through docker and integration tests.
The endpoint returns a legit version:

$ curl 127.0.0.1:3000/api/health
{
  "commit": "1e261642f4",
  "database": "ok",
  "version": "7.3.7"
}

And the folder is properly created.
I also:

  • tested outside the test environment of the collection with what ansible 2.10.5 comes with: it worked.
  • Installed latest collection version through ansible galaxy : it worked

I'm failing at reproducing @gacallea. Can you post the output of a curl command on curl http://your_grafana/api/health ?
Thanks

@gacallea
Copy link
Author

gacallea commented Feb 8, 2021

@rrey it returns only this:

{
  "database": "ok"
}

@rrey
Copy link
Collaborator

rrey commented Feb 8, 2021

well that's unexpected ...

@gacallea
Copy link
Author

gacallea commented Feb 8, 2021

well that's unexpected ...

do I need to enable anything api related in the grafana.ini perhaps?

while this is unexpected every other ansible grafana task works. I'm puzzled.

@rrey
Copy link
Collaborator

rrey commented Feb 8, 2021

Not all modules checks the version. Only the one that are addressing feature introduced after a specific version.
I’m discovering the fact that the health endpoint could not return the version. It would be worth asking Grafana people about this.
Meanwhile we could fallback to consider the version compatible if we don’t get any version

@gacallea
Copy link
Author

gacallea commented Feb 8, 2021

I'm investigating and apparently one needs to be authenticated to get more info from the health api. If I run the curl locally or visit the page, it only returns the dashboard. I'll try authenticating the request and come back to you. That being said, it's weird because the tasks should clearly be authenticated with url_user and url_password.

Regarding the compatible version, I tried downgrading to 7.1.3 because the readme on community grafana lists it as supported. Same issues.

@gacallea
Copy link
Author

gacallea commented Feb 8, 2021

Ok, I found the settings. Under [auth.anonymous] there's a hide_version = true that will not output version and commit. I set this not to disclose info to non-authenticated users for security reasons, and tools should probably not rely on this info as many could choose to hide this info as well as a best practice.

However, I have enabled it to debug the issue and now it returns the following:

{
  "commit": "1e261642f4",
  "database": "ok",
  "version": "7.3.7"
}

Also, I tried running the tasks now that this is in place and:

  • the folders are now created
  • the dashboard install in the created folders

EDIT: it works as expected with the configuration change to hide_version = false

I still think this tools should not rely on such brittle piece of info that people may want to hide for security reasons.

@gacallea
Copy link
Author

gacallea commented Feb 8, 2021

perhaps a possible solution could be for grafana_folder to actually use url_user and url_password to use authentication when checking the health api for version instead of relying on non auth queries?

@rrey
Copy link
Collaborator

rrey commented Feb 8, 2021

perhaps a possible solution could be for grafana_folder to actually use url_user and url_password to use authentication when checking the health api for version instead of relying on non auth queries?

The request already use the the authentication headers to access this endpoint.
We could drop the control on the version since the module docs states that a Grafana version > 5 is required for folders.

@gacallea
Copy link
Author

gacallea commented Feb 8, 2021

perhaps a possible solution could be for grafana_folder to actually use url_user and url_password to use authentication when checking the health api for version instead of relying on non auth queries?

The request already use the the authentication headers to access this endpoint.
We could drop the control on the version since the module docs states that a Grafana version > 5 is required for folders.

sounds like a plan :)

should I open a new request for that to happen? you take care of it?

thank you for all your help, I appreciate you.

@rrey
Copy link
Collaborator

rrey commented Feb 14, 2021

@gacallea I'll keep the version check but I'll add a parameter that allow to skip the control.
You'll just have to enable the parameter in the module call.

rrey pushed a commit that referenced this issue Feb 14, 2021
Parameter allows to skip version check and execute module anyway.

Closes: #147
@rrey rrey added this to the 1.2.0 milestone Feb 14, 2021
rrey pushed a commit that referenced this issue Feb 14, 2021
Parameter allows to skip version check and execute module anyway.

Closes: #147
rrey pushed a commit that referenced this issue Feb 14, 2021
Parameter allows to skip version check and execute module anyway.

Closes: #147
rrey pushed a commit that referenced this issue Feb 14, 2021
Parameter allows to skip version check and execute module anyway.

Closes: #147
rrey pushed a commit that referenced this issue Feb 14, 2021
Parameter allows to skip version check and execute module anyway.

Closes: #147
rrey pushed a commit that referenced this issue Feb 14, 2021
Parameter allows to skip version check and execute module anyway.

Closes: #147
rrey pushed a commit that referenced this issue Feb 14, 2021
Parameter allows to skip version check and execute module anyway.

Closes: #147
rrey pushed a commit that referenced this issue Feb 14, 2021
Parameter allows to skip version check and execute module anyway.

Closes: #147
@rrey rrey closed this as completed in e7fa2b1 Feb 15, 2021
@gacallea
Copy link
Author

thank you so much @rrey!!! I appreciate you :)

about using it, will the documentation update automatically (like with a doc generator from code?)

an example would be nice otherwise. please and thank you

@gacallea
Copy link
Author

ps: this should work?

- name: "Create PRIVATE folder"
  community.grafana.grafana_folder:
    skip_version_check: yes
    state: present
    name: "Private"
    url: "https://{{ grafana_domain }}"
    url_username: "{{ grafana_admin_user }}"
    url_password: "{{ grafana_admin_pass }}"

@rrey
Copy link
Collaborator

rrey commented Feb 16, 2021

Doc update is in the hand of ansible team.
But your code sample is exactly what you should do.
New collection (v1.2.0) was published, let me know about the results

@gacallea
Copy link
Author

Doc update is in the hand of ansible team.
But your code sample is exactly what you should do.
New collection (v1.2.0) was published, let me know about the results

it worked fine :) (I re-enabled the hide version thingie)

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

2 participants