πŸ“Š Adding a Grafana Dashboard

πŸ“– Purpose

This runbook describes how to add a new Grafana dashboard in this repository using the existing dashboard-as-code pattern.

Grafana dashboards in this repo are managed as JSON files in the grafana_setup role and deployed through Ansible provisioning.


🧭 Scope

This runbook applies to:


πŸ›  Add a New Dashboard

1. Add the dashboard JSON file to the Grafana role

Place the dashboard JSON file under:

roles/grafana_setup/files/dashboards

Example:

cp /path/to/your-dashboard.json roles/grafana_setup/files/dashboards/my-dashboard.json

Guidelines:


2. Add Grafana role defaults only when needed

If the dashboard requires new settings, add them in:

roles/grafana_setup/defaults/main/main.yml

Typical examples:

Only add variables that are required for the dashboard you are introducing.


3. Ensure provisioning and copy tasks include the dashboard

Confirm the Grafana role includes the expected provisioning and copy logic in:

roles/grafana_setup/tasks/main.yml

Check that these are present and aligned:

Also confirm the provisioning templates are correct:

roles/grafana_setup/templates/provisioning-datasources.yml.j2
roles/grafana_setup/templates/provisioning-dashboards.yml.j2

For a new dashboard file, add a matching copy task in roles/grafana_setup/tasks/main.yml so the JSON is installed into Grafana’s dashboards directory.


4. Deploy Grafana

Deploy the updated Grafana role with:

ansible-playbook -i inventory/grafana/inventory.ini playbooks/grafana/deploy_grafana.yml

This applies the new dashboard JSON and any related provisioning changes to the Grafana hosts.


βœ… Validate

Before or after deployment, run:

source /opt/python_3.12/bin/activate
ansible-playbook --syntax-check -i inventory/grafana/inventory.ini playbooks/grafana/deploy_grafana.yml
ansible-inventory -i inventory/grafana/inventory.ini --graph
python3 -m json.tool roles/grafana_setup/files/dashboards/my-dashboard.json >/dev/null

These checks confirm:


πŸ” Verify After Deployment

In the Grafana UI, confirm:

If the dashboard is intended to be a landing page or linked dashboard, also confirm the navigation path works as expected.


⚠️ Troubleshooting

Dashboard not visible

Check the following:

Panels show datasource errors

Check the following:

Dashboard duplicates appear

Check the following:


βœ… Summary

To add a new Grafana dashboard:

  1. Add the JSON file under roles/grafana_setup/files/dashboards
  2. Add any required defaults in roles/grafana_setup/defaults/main/main.yml
  3. Ensure roles/grafana_setup/tasks/main.yml copies and provisions the dashboard
  4. Deploy playbooks/grafana/deploy_grafana.yml
  5. Validate the JSON, deployment path, and dashboard behavior in Grafana

The existing grafana_setup role is the source of truth for how dashboards are provisioned and deployed in this repository.