|
93 | 93 | - "(grafana_manage_repo)" |
94 | 94 | environment: "{{ grafana_environment }}" |
95 | 95 | 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) }}" |
96 | 100 | - name: "Import Grafana apt gpg key" |
97 | 101 | ansible.builtin.get_url: |
98 | 102 | url: "{{ grafana_apt_key }}" |
99 | 103 | dest: /usr/share/keyrings/grafana.asc |
100 | 104 | mode: "0644" |
101 | | - |
| 105 | + when: not __use_deb822 |
102 | 106 | - 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 |
104 | 108 | ansible.builtin.apt_repository: |
105 | 109 | repo: "{{ grafana_apt_repo }}" |
106 | | - state: present |
107 | 110 | update_cache: true |
108 | 111 | - name: "Add Grafana apt repository" |
109 | | - when: ansible_facts['os_family'] == 'Debian' and (ansible_facts['distribution_version'] | version('12', '>')) |
| 112 | + when: __use_deb822 |
110 | 113 | ansible.builtin.deb822_repository: |
111 | 114 | name: "{{ grafana_apt_name }}" |
112 | 115 | types: deb |
113 | | - uri: "{{ grafana_apt_repo_uri }}" |
| 116 | + uris: "{{ grafana_apt_repo_uri }}" |
114 | 117 | suites: "{{ grafana_apt_release_channel }}" |
115 | 118 | components: |
116 | 119 | - main |
117 | 120 | architectures: |
118 | 121 | - "{{ 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 |
133 | 128 |
|
134 | 129 | - name: "Install Grafana" |
135 | 130 | ansible.builtin.package: |
|
0 commit comments