Files
ansible-pull/roles/apt_repos/tasks/add.yml
T
rene 97c64189c5 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.
2026-10-23 09:13:42 +02:00

48 lines
1.8 KiB
YAML
Executable File

---
# 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 }}"