feat: initial installation role for grafana

This commit is contained in:
2026-05-24 17:13:39 +02:00
commit 268f86ef38
8 changed files with 139 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.retry

28
README.md Normal file
View File

@@ -0,0 +1,28 @@
# ansible-role-grafana
Installs Grafana on Debian/Ubuntu (via apt.grafana.com) and RHEL/Fedora
(via rpm.grafana.com). Installs the OSS edition by default.
## Requirements
- Ansible >= 2.14
## Role Variables
| Variable | Default | Description |
|---|---|---|
| `grafana_package` | `grafana` | Package name (`grafana` or `grafana-enterprise`) |
| `grafana_service_enabled` | `true` | Enable service at boot |
| `grafana_service_state` | `started` | Service state after installation |
## Example Playbook
```yaml
- hosts: servers
roles:
- role: ansible-role-grafana
```
## License
MIT

4
defaults/main.yml Normal file
View File

@@ -0,0 +1,4 @@
---
grafana_package: grafana
grafana_service_enabled: true
grafana_service_state: started

1
handlers/main.yml Normal file
View File

@@ -0,0 +1 @@
---

17
meta/main.yml Normal file
View File

@@ -0,0 +1,17 @@
---
galaxy_info:
author: mathieu
description: Install Grafana on Debian and RedHat based distributions
license: MIT
min_ansible_version: "2.14"
platforms:
- name: Debian
versions: [bullseye, bookworm]
- name: Ubuntu
versions: [focal, jammy, noble]
- name: EL
versions: ["8", "9"]
- name: Fedora
versions: [all]
galaxy_tags: [grafana, monitoring, dashboards]
dependencies: []

50
tasks/debian.yml Normal file
View File

@@ -0,0 +1,50 @@
---
- name: Install Grafana prerequisites
ansible.builtin.apt:
name:
- apt-transport-https
- software-properties-common
- wget
state: present
update_cache: true
become: true
- name: Create Grafana keyring directory
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
become: true
- name: Download Grafana GPG key
ansible.builtin.shell:
cmd: wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor -o /etc/apt/keyrings/grafana.gpg
creates: /etc/apt/keyrings/grafana.gpg
become: true
- name: Set Grafana GPG key permissions
ansible.builtin.file:
path: /etc/apt/keyrings/grafana.gpg
mode: '0644'
become: true
- name: Add Grafana apt repository
ansible.builtin.copy:
content: "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main\n"
dest: /etc/apt/sources.list.d/grafana.list
mode: '0644'
become: true
- name: Install Grafana
ansible.builtin.apt:
name: "{{ grafana_package }}"
state: present
update_cache: true
become: true
- name: Enable and start Grafana service
ansible.builtin.systemd:
name: grafana-server
enabled: "{{ grafana_service_enabled }}"
state: "{{ grafana_service_state }}"
become: true

9
tasks/main.yml Normal file
View File

@@ -0,0 +1,9 @@
---
- name: Assert supported OS family
ansible.builtin.assert:
that:
- ansible_os_family in ['Debian', 'RedHat']
fail_msg: "Unsupported OS family: {{ ansible_os_family }}"
- name: Include OS-specific installation tasks
ansible.builtin.include_tasks: "{{ ansible_os_family | lower }}.yml"

29
tasks/redhat.yml Normal file
View File

@@ -0,0 +1,29 @@
---
- name: Add Grafana yum repository
ansible.builtin.copy:
content: |
[grafana]
name=grafana
baseurl=https://rpm.grafana.com
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://rpm.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
dest: /etc/yum.repos.d/grafana.repo
mode: '0644'
become: true
- name: Install Grafana
ansible.builtin.dnf:
name: "{{ grafana_package }}"
state: present
become: true
- name: Enable and start Grafana service
ansible.builtin.systemd:
name: grafana-server
enabled: "{{ grafana_service_enabled }}"
state: "{{ grafana_service_state }}"
become: true