Skip to content

Commit b9bac4a

Browse files
authored
fix: broken Grafana apt repository addition (#454)
1 parent 83a2d47 commit b9bac4a

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

roles/grafana/tasks/install.yml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,43 +93,38 @@
9393
- "(grafana_manage_repo)"
9494
environment: "{{ grafana_environment }}"
9595
block:
96+
- name: "Use deb822 format?"
97+
ansible.builtin.set_fact:
98+
__use_deb822: "{{ (ansible_facts['distribution'] == 'Debian' and (ansible_facts['distribution_major_version'] | int) >= 12) or
99+
(ansible_facts['distribution'] == 'Ubuntu' and (ansible_facts['distribution_major_version'] | int) >= 24) }}"
96100
- name: "Import Grafana apt gpg key"
97101
ansible.builtin.get_url:
98102
url: "{{ grafana_apt_key }}"
99103
dest: /usr/share/keyrings/grafana.asc
100104
mode: "0644"
101-
105+
when: not __use_deb822
102106
- name: "Add Grafana apt repository"
103-
when: not (ansible_facts['os_family'] == 'Debian' and (ansible_facts['distribution_version'] | version('12', '>')))
107+
when: not __use_deb822
104108
ansible.builtin.apt_repository:
105109
repo: "{{ grafana_apt_repo }}"
106-
state: present
107110
update_cache: true
108111
- name: "Add Grafana apt repository"
109-
when: ansible_facts['os_family'] == 'Debian' and (ansible_facts['distribution_version'] | version('12', '>'))
112+
when: __use_deb822
110113
ansible.builtin.deb822_repository:
111114
name: "{{ grafana_apt_name }}"
112115
types: deb
113-
uri: "{{ grafana_apt_repo_uri }}"
116+
uris: "{{ grafana_apt_repo_uri }}"
114117
suites: "{{ grafana_apt_release_channel }}"
115118
components:
116119
- main
117120
architectures:
118121
- "{{ grafana_apt_arch }}"
119-
# could also be inlined or we can specify the url directly here
120-
signed_by: /usr/share/keyrings/grafana.asc
121-
repo: "{{ grafana_apt_repo }}"
122-
state: present
123-
124-
# maybe too restrictive
125-
check_valid_until: true
126-
allow_downgrade_to_insecure: false
127-
allow_insecure: false
128-
allow_weak: false
129-
check_date: true
130-
enabled: true
131-
# TODO
132-
# update_cache: true # This module will not automatically update caches, call the ansible.builtin.apt module based on the changed state.
122+
signed_by: "{{ grafana_apt_key }}"
123+
register: __update_cache
124+
- name: "Update apt cache"
125+
ansible.builtin.apt:
126+
update_cache: true
127+
when: __update_cache is defined and __update_cache.changed
133128

134129
- name: "Install Grafana"
135130
ansible.builtin.package:

0 commit comments

Comments
 (0)