ansible-role-grafana/tasks/main.yml

111 lines
3.4 KiB
YAML
Raw Normal View History

2022-06-20 18:58:45 +02:00
---
- name: Remove grafana
when: not grafana_enabled
tags: [grafana]
block:
- name: Ensure that grafana is stopped and disabled
2024-01-10 18:28:06 +01:00
ansible.builtin.service:
name: grafana-server
state: stopped
enabled: false
- name: Remove the grafana deb packages
2024-01-10 18:28:06 +01:00
ansible.builtin.apt:
name: "{{ grafana_packages }}"
state: absent
- name: Install the grafana deb repository
2024-01-10 18:28:06 +01:00
ansible.builtin.apt_repository:
repo: '{{ grafana_repo }}'
state: absent
update_cache: true
- name: Install grafana
when: grafana_enabled
2022-12-20 17:39:58 +01:00
tags: [grafana]
block:
2024-01-10 18:28:06 +01:00
- name: Ensure that the directory were the GPG key is stored exists
2023-10-26 19:50:52 +02:00
ansible.builtin.file:
2024-01-10 18:28:06 +01:00
dest: /etc/apt/keyrings
2023-10-26 19:50:52 +02:00
state: directory
mode: "0755"
owner: root
group: root
- name: Install the grafana repo key
2024-01-10 18:28:06 +01:00
ansible.builtin.get_url:
url: "{{ grafana_repo_key_url }}"
dest: "{{ grafana_repo_key_file }}"
2023-01-30 18:32:32 +01:00
owner: root
group: root
2024-01-10 18:28:06 +01:00
mode: "0644"
2023-10-26 19:50:52 +02:00
tags: [grafana, grafana_repo_key]
2024-01-10 18:28:06 +01:00
- name: Install the grafana repository for Ubuntu
ansible.builtin.deb822_repository:
name: grafana-com
types: [deb]
uris: "{{ grafana_repo_url }}"
components: "{{ grafana_repo_components }}"
suites: "{{ grafana_repo_suites }}"
signed_by: "{{ grafana_repo_key_file }}"
2023-01-30 18:32:32 +01:00
state: present
2024-01-10 18:28:06 +01:00
enabled: true
2022-12-20 17:39:58 +01:00
2024-01-10 18:28:06 +01:00
- name: Basic grafana configuration
community.general.ini_file:
2022-12-20 17:39:58 +01:00
path: /etc/grafana/grafana.ini
section: "{{ item.section }}"
option: "{{ item.option }}"
value: "{{ item.value }}"
2022-12-20 13:03:01 +01:00
state: "{{ item.state | default('present') }}"
2022-12-20 17:39:58 +01:00
mode: "0440"
2022-12-20 13:03:01 +01:00
owner: root
group: grafana
2022-12-20 17:39:58 +01:00
loop: "{{ grafana_conf }}"
2022-12-20 13:03:01 +01:00
notify: Restart grafana
2022-12-20 17:39:58 +01:00
tags: [grafana, grafana_conf]
2022-12-20 13:03:01 +01:00
- name: Add additional grafana configurations
2024-01-10 18:28:06 +01:00
community.general.ini_file:
2022-12-20 17:39:58 +01:00
path: /etc/grafana/grafana.ini
section: "{{ item.section }}"
option: "{{ item.option }}"
value: "{{ item.value }}"
2022-12-20 13:03:01 +01:00
state: "{{ item.state | default('present') }}"
2022-12-20 17:39:58 +01:00
mode: "0440"
owner: root
group: grafana
2022-12-20 17:39:58 +01:00
loop: "{{ grafana_additional_conf }}"
notify: Restart grafana
2022-12-20 17:39:58 +01:00
tags: [grafana, grafana_conf]
2022-12-20 13:03:01 +01:00
- name: Install the grafana LDAP configuration file
ansible.builtin.template:
2022-12-20 17:39:58 +01:00
src: "{{ item }}.j2"
dest: /etc/grafana/{{ item }}
2024-01-10 18:28:06 +01:00
mode: "0440"
owner: root
group: grafana
2022-12-20 17:39:58 +01:00
loop: "{{ grafana_ldap_conf_file }}"
notify: Restart grafana
when: grafana_ldap_auth
2022-12-20 17:39:58 +01:00
tags: [grafana, grafana_conf, grafana_ldap]
- name: Create the local dashboards directory
2024-01-10 18:28:06 +01:00
ansible.builtin.file:
dest: /var/lib/grafana/dashboards
state: directory
mode: "0755"
owner: grafana
group: grafana
- name: Install additional plugins, if any
2024-01-10 18:28:06 +01:00
community.grafana.grafana_plugin:
2022-12-20 17:39:58 +01:00
name: "{{ item.name }}"
2022-12-19 18:57:51 +01:00
state: "{{ item.state | default('present') }}"
grafana_repo: "{{ item.repo | default('https://grafana.com/api/plugins') }}"
2022-12-20 17:39:58 +01:00
loop: "{{ grafana_additional_plugins }}"
tags: [grafana, grafana_plugins]
- name: Ensure that grafana is enabled and running
2024-01-10 18:28:06 +01:00
ansible.builtin.service:
name: grafana-server
state: started
enabled: true