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

Grafana dashboard should return dashboard id too #235

Open
Lusitaniae opened this issue Apr 12, 2022 · 0 comments
Open

Grafana dashboard should return dashboard id too #235

Lusitaniae opened this issue Apr 12, 2022 · 0 comments

Comments

@Lusitaniae
Copy link
Contributor

Lusitaniae commented Apr 12, 2022

https://docs.ansible.com/ansible/latest/collections/community/grafana/grafana_dashboard_module.html

As documented here only the uid of the referenced dashboard is returned, however to interact with Grafana's Dashboad permissions API we'd need to use the ID instead of UID (the APIs seem to be inconsistent, the folder permissions API requires uid?)

Also the example Sample: 51 looks inaccurate, as you're likely to get a "random" string looking like 7tCqfiv7k instead of a numeric id

https://grafana.com/docs/grafana/latest/http_api/dashboard_permissions/#update-permissions-for-a-dashboard

Work around using ansible uri to interact with API

- name: Import Grafana dashboard
  community.grafana.grafana_dashboard:
      ... args list
  register: dashboard

- name: Get dashboard id
  uri:
    url: "{{ grafana_url }}/api/dashboards/uid/{{ dashboard.results[0].uid }}"
    return_content: yes
    headers:
      Authorization: "Basic {{ (grafana_user + ':' + grafana_pass_decoded )| b64encode }}"
  register: dashboard_id

- name: Set dashboard permissions
  uri:
    url: "{{ grafana_url }}/api/dashboards/id/{{ dashboard_id.json.dashboard.id }}/permissions"
    method: POST
    body: | # 1 - viewer | 2 - editor # teamId requires int here, otherwise returns 400
        {"items": [
            {"teamId": {{ team.team.id | int }}, "permission": 1}
        ]}
    body_format: json
    return_content: yes
    headers:
      Authorization: "Basic {{ (grafana_user + ':' + grafana_pass_decoded )| b64encode }}"
  register: folder_perms
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

1 participant