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

Broken task "Import grafana dashboards via api" from roles/grafana/tasks/dashboards.yml #229

Open
kysrpex opened this issue Jun 24, 2024 · 0 comments

Comments

@kysrpex
Copy link

kysrpex commented Jun 24, 2024

Hi! I attempted to use the role grafana.grafana.grafana without provisioning, that is, setting grafana_use_provisioning to false and I stumbled, first upon the following issue (to get this I set no_log to false for task "Import grafana dashboards via api" from roles/grafana/tasks/dashboards.yml).

[...]$ ansible-playbook grafana.yml

PLAY [Grafana] ************************************************************************

TASK [Gathering Facts] ****************************************************************
ok: [xxx.xxx.xxx.xxx]

...

TASK [grafana.grafana.grafana : Import grafana dashboards via api] *********************************************************************************************************************
failed: [xxx.xxx.xxx.xxx] (item=/home/.../files/grafana/Alerts.json) => {"ansible_loop_var": "item", "changed": false, "item": "/home/.../files/grafana/Alerts.json", "msg": "Unsupported parameters for (community.grafana.grafana_dashboard) module: message. Supported parameters include: client_cert, client_key, commit_message, dashboard_id, dashboard_revision, folder, grafana_api_key, org_id, org_name, overwrite, path, slug, state, uid, url, url_password, url_username, use_proxy, validate_certs (dashboard_url, grafana_password, grafana_url, grafana_user)."}
... (one failure for each dashboard)
failed: [xxx.xxx.xxx.xxx] (item=/home/.../files/grafana/uWSGI.json) => {"ansible_loop_var": "item", "changed": false, "item": "/home/.../files/grafana/uWSGI.json", "msg": "Unsupported parameters for (community.grafana.grafana_dashboard) module: message. Supported parameters include: client_cert, client_key, commit_message, dashboard_id, dashboard_revision, folder, grafana_api_key, org_id, org_name, overwrite, path, slug, state, uid, url, url_password, url_username, use_proxy, validate_certs (dashboard_url, grafana_password, grafana_url, grafana_user)."}

PLAY RECAP *****************************************************************************************************************************************************************************
xxx.xxx.xxx.xxx             : ok=87   changed=1    unreachable=0    failed=1    skipped=75   rescued=0    ignored=0   

Parameter message is not accepted by module community.grafana.grafana_dashboard. I am using version 2.0.0 of the community.grafana collection. In the changelog, they state,

  • removed deprecated message argument in grafana_dashboard

so it makes sense. However, I have tried with earlier versions too, for example v1.9.1 or 1.8.0. They also fail because the module contains the following lines of code. In fact, all available versions except v0.1.0, v1.9.0 (apparently by mistake) and the latest (v2.0.0) contain them.

    if "message" in module.params:
        module.fail_json(
            msg="'message' is reserved keyword, please change this parameter to 'commit_message'"
        )

Therefore, I actually expect the task to fail regardless of the version of community.grafana that is installed.


Second, if I comment the line message: "Updated by ansible role {{ ansible_role_name }}" from that task to bypass the issue, then I face another issue.

[...]$ ansible-playbook grafana.yml

PLAY [Grafana] ************************************************************************

TASK [Gathering Facts] ****************************************************************
ok: [xxx.xxx.xxx.xxx]

...

TASK [grafana.grafana.grafana : Import grafana dashboards via api] *********************************************************************************************************************
failed: [xxx.xxx.xxx.xxx] (item=/home/.../files/grafana/Alerts.json) => {"ansible_loop_var": "item", "changed": false, "item": "/home/.../files/grafana/Alerts.json", "msg": "error : Can't load json file [Errno 2] No such file or directory: '/home/.../files/grafana/Alerts.json'"}
... (one failure for each dashboard)
failed: [xxx.xxx.xxx.xxx] (item=/home/.../files/grafana/uWSGI.json) => {"ansible_loop_var": "item", "changed": false, "item": "/home/.../files/grafana/uWSGI.json", "msg": "error : Can't load json file [Errno 2] No such file or directory: '/home/.../files/grafana/uWSGI.json'"}

PLAY RECAP *****************************************************************************************************************************************************************************
xxx.xxx.xxx.xxx             : ok=87   changed=1    unreachable=0    failed=1    skipped=75   rescued=0    ignored=0   

This actually happens because community.grafana.grafana_dashboard is looking for the dashboards on the server rather than on the control node. To verify this, I copied /home/.../files/grafana/Alerts.json to the same directory on the server before running the playbook, then after running it I got the following output.

[...]$ ansible-playbook grafana.yml

PLAY [Grafana] ************************************************************************

TASK [Gathering Facts] ****************************************************************
ok: [xxx.xxx.xxx.xxx]

...

TASK [grafana.grafana.grafana : Import grafana dashboards via api] *********************************************************************************************************************
ok: [xxx.xxx.xxx.xxx] => (item=/home/.../files/grafana/Alerts.json)
... (one failure for each remaining dashboard)
failed: [xxx.xxx.xxx.xxx] (item=/home/.../files/grafana/uWSGI.json) => {"ansible_loop_var": "item", "changed": false, "item": "/home/.../files/grafana/uWSGI.json", "msg": "error : Can't load json file [Errno 2] No such file or directory: '/home/.../files/grafana/uWSGI.json'"}

PLAY RECAP *****************************************************************************************************************************************************************************
xxx.xxx.xxx.xxx             : ok=87   changed=1    unreachable=0    failed=1    skipped=75   rescued=0    ignored=0   

The dashboard for which the task completed successfully shows up in Grafana, so fixing these two issues should be all that's needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant