community.grafana.grafana_dashboard module – Manage Grafana dashboards

Note

This module is part of the community.grafana collection (version 1.9.1).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.grafana.

To use it in a playbook, specify: community.grafana.grafana_dashboard.

New in community.grafana 1.0.0

Synopsis

  • Create, update, delete, export Grafana dashboards via API.

Parameters

Parameter

Comments

client_cert

path

PEM formatted certificate chain file to be used for SSL client authentication.

This file can also include the key as well, and if the key is included, client_key is not required

client_key

path

PEM formatted file that contains your private key to be used for SSL client authentication.

If client_cert contains both the certificate and key, this option is not required.

commit_message

aliases: message

string

Set a commit message for the version history.

Only used when state is present.

message alias is deprecated in Ansible 2.10, since it is used internally by Ansible Core Engine.

dashboard_id

string

added in community.grafana 1.0.0

Public Grafana.com dashboard id to import

dashboard_revision

string

added in community.grafana 1.0.0

Revision of the public grafana dashboard to import

Default: "1"

folder

string

added in community.grafana 1.0.0

The Grafana folder where this dashboard will be imported to.

Default: "General"

grafana_api_key

string

The Grafana API key.

If set, url_username and url_password will be ignored.

org_id

integer

The Grafana organization ID where the dashboard will be imported / exported / deleted.

Not used when grafana_api_key is set, because the grafana_api_key only belongs to one organization.

Mutually exclusive with org_name.

Default: 1

org_name

string

The Grafana organization name where the dashboard will be imported / exported / deleted.

Not used when grafana_api_key is set, because the grafana_api_key only belongs to one organization.

Mutually exclusive with org_id.

overwrite

boolean

Override existing dashboard when state is present.

Choices:

  • false ← (default)

  • true

path

aliases: dashboard_url

string

The path to the json file containing the Grafana dashboard to import or export.

A http URL is also accepted (since 2.10).

Required if state is export or present.

slug

string

Deprecated since Grafana 5. Use grafana dashboard uid instead.

slug of the dashboard. It’s the friendly url name of the dashboard.

When state is present, this parameter can override the slug in the meta section of the json file.

If you want to import a json dashboard exported directly from the interface (not from the api), you have to specify the slug parameter because there is no meta section in the exported json.

state

string

State of the dashboard.

Choices:

  • "absent"

  • "export"

  • "present" ← (default)

uid

string

added in community.grafana 1.0.0

uid of the dashboard to export when state is export or absent.

url

aliases: grafana_url

string / required

The Grafana URL.

url_password

aliases: grafana_password

string

The Grafana password for API authentication.

Default: "admin"

url_username

aliases: grafana_user

string

The Grafana user for API authentication.

Default: "admin"

use_proxy

boolean

If false, it will not use a proxy, even if one is defined in an environment variable on the target hosts.

Choices:

  • false

  • true ← (default)

validate_certs

boolean

If false, SSL certificates will not be validated.

This should only set to false used on personally controlled sites using self-signed certificates.

Choices:

  • false

  • true ← (default)

Examples

- name: Import Grafana dashboard foo
  community.grafana.grafana_dashboard:
    grafana_url: http://grafana.company.com
    grafana_api_key: "{{ grafana_api_key }}"
    state: present
    commit_message: Updated by ansible
    overwrite: true
    path: /path/to/dashboards/foo.json

- name: Import Grafana dashboard Zabbix
  community.grafana.grafana_dashboard:
    grafana_url: http://grafana.company.com
    grafana_api_key: "{{ grafana_api_key }}"
    folder: zabbix
    dashboard_id: 6098
    dashboard_revision: 1

- name: Import Grafana dashboard zabbix
  community.grafana.grafana_dashboard:
    grafana_url: http://grafana.company.com
    grafana_api_key: "{{ grafana_api_key }}"
    folder: public
    dashboard_url: https://grafana.com/api/dashboards/6098/revisions/1/download

- name: Export dashboard
  community.grafana.grafana_dashboard:
    grafana_url: http://grafana.company.com
    grafana_user: "admin"
    grafana_password: "{{ grafana_password }}"
    org_id: 1
    state: export
    uid: "000000653"
    path: "/path/to/dashboards/000000653.json"

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

uid

string

uid or slug of the created / deleted / exported dashboard.

Returned: success

Sample: "51"

Authors

  • Thierry Sallé (@seuf)