Fix the repository definition.

This commit is contained in:
Andrea Dell'Amico 2024-01-10 18:28:06 +01:00
parent 73617dc274
commit 1eb68fdd6a
Signed by: andrea.dellamico
GPG Key ID: 147ABE6CEB9E20FF
2 changed files with 49 additions and 27 deletions

View File

@ -1,7 +1,12 @@
--- ---
grafana_repo_key: https://apt.grafana.com/gpg.key grafana_repo_key_url: https://apt.grafana.com/gpg.key
grafana_repo: "deb [signed-by=/etc/apt/trusted.gpg.d/grafana.gpg] https://apt.grafana.com stable main" grafana_repo_key_file: /etc/apt/keyrings/grafana.gpg
grafana_pkg_state: latest grafana_repo_url: "https://apt.grafana.com"
grafana_repo_components:
- main
grafana_repo_suites:
- stable
grafana_pkg_state: present
grafana_packages: grafana_packages:
- grafana - grafana

View File

@ -4,46 +4,55 @@
tags: [grafana] tags: [grafana]
block: block:
- name: Ensure that grafana is stopped and disabled - name: Ensure that grafana is stopped and disabled
service: name=grafana-server state=stopped enabled=no ansible.builtin.service:
name: grafana-server
state: stopped
enabled: false
- name: Remove the grafana deb packages - name: Remove the grafana deb packages
apt: name={{ grafana_packages }} state=absent ansible.builtin.apt:
name: "{{ grafana_packages }}"
state: absent
- name: Install the grafana deb repository - name: Install the grafana deb repository
apt_repository: repo='{{ grafana_repo }}' state=absent update_cache=yes ansible.builtin.apt_repository:
repo: '{{ grafana_repo }}'
state: absent
update_cache: true
- name: Install grafana - name: Install grafana
when: grafana_enabled when: grafana_enabled
tags: [grafana] tags: [grafana]
block: block:
- name: Create a directory to store the repo keys - name: Ensure that the directory were the GPG key is stored exists
ansible.builtin.file: ansible.builtin.file:
dest: /etc/apt/trusted.gpg.d dest: /etc/apt/keyrings
state: directory state: directory
mode: "0755" mode: "0755"
owner: root owner: root
group: root group: root
- name: Install the grafana repo key - name: Install the grafana repo key
get_url: ansible.builtin.get_url:
url: "{{ grafana_repo_key }}" url: "{{ grafana_repo_key_url }}"
dest: /etc/apt/trusted.gpg.d/grafana.gpg dest: "{{ grafana_repo_key_file }}"
state: present
owner: root owner: root
group: root group: root
mode: 0644 mode: "0644"
tags: [grafana, grafana_repo_key] tags: [grafana, grafana_repo_key]
- name: Install the grafana deb repository - name: Install the grafana repository for Ubuntu
apt_repository: ansible.builtin.deb822_repository:
repo: "{{ grafana_repo }}" name: grafana-com
types: [deb]
uris: "{{ grafana_repo_url }}"
components: "{{ grafana_repo_components }}"
suites: "{{ grafana_repo_suites }}"
signed_by: "{{ grafana_repo_key_file }}"
state: present state: present
update_cache: true enabled: true
- name: Install the grafana deb packages - name: Basic grafana configuration
apt: name={{ grafana_packages }} state={{ grafana_pkg_state }} update_cache=yes cache_valid_time=1800 community.general.ini_file:
- name: Install the grafana configuration
ansible.builtin.ini_file:
path: /etc/grafana/grafana.ini path: /etc/grafana/grafana.ini
section: "{{ item.section }}" section: "{{ item.section }}"
option: "{{ item.option }}" option: "{{ item.option }}"
@ -56,7 +65,7 @@
notify: Restart grafana notify: Restart grafana
tags: [grafana, grafana_conf] tags: [grafana, grafana_conf]
- name: Add additional grafana configurations - name: Add additional grafana configurations
ansible.builtin.ini_file: community.general.ini_file:
path: /etc/grafana/grafana.ini path: /etc/grafana/grafana.ini
section: "{{ item.section }}" section: "{{ item.section }}"
option: "{{ item.option }}" option: "{{ item.option }}"
@ -72,7 +81,7 @@
ansible.builtin.template: ansible.builtin.template:
src: "{{ item }}.j2" src: "{{ item }}.j2"
dest: /etc/grafana/{{ item }} dest: /etc/grafana/{{ item }}
mode: 0440 mode: "0440"
owner: root owner: root
group: grafana group: grafana
loop: "{{ grafana_ldap_conf_file }}" loop: "{{ grafana_ldap_conf_file }}"
@ -80,14 +89,22 @@
when: grafana_ldap_auth when: grafana_ldap_auth
tags: [grafana, grafana_conf, grafana_ldap] tags: [grafana, grafana_conf, grafana_ldap]
- name: Create the local dashboards directory - name: Create the local dashboards directory
file: dest=/var/lib/grafana/dashboards state=directory mode=0755 owner=grafana group=grafana ansible.builtin.file:
dest: /var/lib/grafana/dashboards
state: directory
mode: "0755"
owner: grafana
group: grafana
- name: Install additional plugins, if any - name: Install additional plugins, if any
grafana_plugin: community.grafana.grafana_plugin:
name: "{{ item.name }}" name: "{{ item.name }}"
state: "{{ item.state | default('present') }}" state: "{{ item.state | default('present') }}"
grafana_repo: "{{ item.repo | default('https://grafana.com/api/plugins') }}" grafana_repo: "{{ item.repo | default('https://grafana.com/api/plugins') }}"
loop: "{{ grafana_additional_plugins }}" loop: "{{ grafana_additional_plugins }}"
tags: [grafana, grafana_plugins] tags: [grafana, grafana_plugins]
- name: Ensure that grafana is enabled and running - name: Ensure that grafana is enabled and running
service: name=grafana-server state=started enabled=yes ansible.builtin.service:
name: grafana-server
state: started
enabled: true