apt: use deb822_repository only on ansible-core >= 2.15

ansible.builtin.deb822_repository was added in ansible-core 2.15. Hosts
running an older ansible-core cannot use it at all, so gate the choice of
module on the runtime version.

Introduce the shared role apt_repos (tasks_from: add) which takes a
single structured apt_repo dict and:
- uses deb822_repository when ansible_version.full >= 2.15 and removes
  the legacy .list file,
- falls back to apt_repository (still available before its removal in
  2.25) and builds the equivalent 'deb [opts] uri suite components' line
  otherwise.

All six repository definitions now go through the role, keeping the
deb822 and legacy representations in sync from one source of truth. The
backup role's repository task keeps its tags via apply, and its tailscale
install updates the apt cache explicitly since the previously notified
'update apt cache' handler does not exist.
This commit is contained in:
rene committed 2026-10-23 09:13:42 +02:00
1 parent 83e6accdc1
commit 97c64189c5
7 files changed
+159 -104

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
---
# Standardwerte für roles/apt_repos/tasks/add.yml
#
# Erwartete Variable: apt_repo (dict)
# name (Pflicht) Repo-Name (deb822: X-Repolib-Name und Dateiname)
# uris (Pflicht) Basis-URL des Repositories
# suites (Pflicht) Suite/Codename oder Pfad (Pfad muss auf "/" enden)
# components (optional) Liste der Komponenten (bei Pfad-Suite weglassen)
# types (optional) [deb] (Default) oder [deb, deb-src]
# signed_by (optional) Pfad zum Keyring
# architectures (optional) Liste der Architekturen
# mode (optional) Dateimodus, Default "0644"
# legacy_file (optional) Dateiname der alten .list, Default: name
# notify (optional) Handler, Default: apt_update
apt_repo_types: "{{ apt_repo.types | default(['deb']) }}"
apt_repo_legacy_file: "{{ apt_repo.legacy_file | default(apt_repo.name) }}"
apt_repo_notify: "{{ apt_repo.notify | default('apt_update') }}"
apt_repo_arch_option: "{{ ('arch=' ~ (apt_repo.architectures | join(','))) if apt_repo.architectures is defined else '' }}"
apt_repo_signed_option: "{{ ('signed-by=' ~ apt_repo.signed_by) if apt_repo.signed_by is defined else '' }}"
apt_repo_legacy_options: "{{ (apt_repo_arch_option ~ ' ' ~ apt_repo_signed_option) | trim }}"
apt_repo_legacy_suffix: >-
{{ (' [' ~ apt_repo_legacy_options ~ ']') if apt_repo_legacy_options else '' }}
{{ apt_repo.uris }} {{ apt_repo.suites }}{{ (' ' ~ (apt_repo.components | join(' '))) if apt_repo.components is defined else '' }}
+47
View File
@@ -0,0 +1,47 @@
---
# Fügt ein APT-Repository hinzu.
#
# Auf ansible-core >= 2.15 wird ansible.builtin.deb822_repository verwendet
# (Modul ab 2.15 verfügbar), auf älteren Versionen fällt der Task auf das
# (dort noch nicht abgekündigte) ansible.builtin.apt_repository zurück.
#
# Parameter: siehe roles/apt_repos/defaults/main.yml (Variable apt_repo).
- name: apt_repos | validate parameters
ansible.builtin.assert:
that:
- apt_repo is defined
- apt_repo.name is defined
- apt_repo.uris is defined
- apt_repo.suites is defined
fail_msg: "apt_repo benötigt mindestens die Schlüssel name, uris und suites."
quiet: true
- name: "apt_repos | {{ apt_repo.name }} | add repository (deb822, ansible-core >= 2.15)"
ansible.builtin.deb822_repository:
name: "{{ apt_repo.name }}"
types: "{{ apt_repo_types }}"
uris: "{{ apt_repo.uris }}"
suites: "{{ apt_repo.suites }}"
components: "{{ apt_repo.components | default(omit) }}"
signed_by: "{{ apt_repo.signed_by | default(omit) }}"
architectures: "{{ apt_repo.architectures | default(omit) }}"
mode: "{{ apt_repo.mode | default('0644') }}"
when: ansible_version.full is version('2.15', '>=')
notify: "{{ apt_repo_notify }}"
- name: "apt_repos | {{ apt_repo.name }} | remove legacy .list file"
ansible.builtin.file:
path: "/etc/apt/sources.list.d/{{ apt_repo_legacy_file }}.list"
state: absent
when: ansible_version.full is version('2.15', '>=')
notify: "{{ apt_repo_notify }}"
- name: "apt_repos | {{ apt_repo.name }} | add repository (apt_repository, ansible-core < 2.15)"
ansible.builtin.apt_repository:
repo: "{{ item }}{{ apt_repo_legacy_suffix }}"
state: present
filename: "{{ apt_repo_legacy_file }}"
loop: "{{ apt_repo_types }}"
when: ansible_version.full is version('2.15', '<')
notify: "{{ apt_repo_notify }}"