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

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