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 }}"
@@ -47,30 +47,31 @@
mode: '0644'
when: ansible_facts['distribution'] in [ "Debian", "Ubuntu", "Linux Mint" ]
- name: backup | tailscale | remove legacy repository file (debian-based)
tags: packages,system,system setup,tailscale
file:
path: /etc/apt/sources.list.d/tailscale.list
state: absent
when: ansible_facts['distribution'] in [ "Debian", "Ubuntu", "Linux Mint" ]
notify: update apt cache
- name: backup | tailscale | add tailscale repository (debian-based)
tags: packages,system,system setup,tailscale
deb822_repository:
name: tailscale
types: deb
uris: "https://pkgs.tailscale.com/stable/{{ ansible_facts['distribution'] | lower }}"
suites: "{{ ansible_facts['distribution_release'] }}"
components:
- main
signed_by: /usr/share/keyrings/tailscale-archive-keyring.gpg
include_role:
name: apt_repos
tasks_from: add
apply:
tags:
- packages
- system
- system setup
- tailscale
vars:
apt_repo:
name: tailscale
uris: "https://pkgs.tailscale.com/stable/{{ ansible_facts['distribution'] | lower }}"
suites: "{{ ansible_facts['distribution_release'] }}"
components:
- main
signed_by: /usr/share/keyrings/tailscale-archive-keyring.gpg
when: ansible_facts['distribution'] in [ "Debian", "Ubuntu", "Linux Mint" ]
notify: update apt cache
- name: backup | tailscale | install tailscale (debian-based)
tags: packages,system,system setup,tailscale
apt:
name: tailscale
state: latest
update_cache: true
when: ansible_facts['distribution'] in [ "Debian", "Ubuntu", "Linux Mint" ]
+20 -30
View File
@@ -39,40 +39,30 @@
- { name: "jitsi", url: "https://download.jitsi.org/jitsi-key.gpg.key" }
when: preinstalled == false or preinstalled is not defined
- name: jitsimeet | remove legacy prosody repository file
file:
path: /etc/apt/sources.list.d/prosody.list
state: absent
notify: apt_update
when: preinstalled == false or preinstalled is not defined
- name: jitsimeet | add prosody repository
deb822_repository:
name: prosody
types: deb
uris: "https://packages.prosody.im/debian"
suites: "{{ ansible_facts['distribution_release'] }}"
components:
- main
signed_by: /usr/share/keyrings/prosody-archive-keyring.gpg
notify: apt_update
when: preinstalled == false or preinstalled is not defined
- name: jitsimeet | remove legacy jitsi repository file
file:
path: /etc/apt/sources.list.d/jitsi-stable.list
state: absent
notify: apt_update
include_role:
name: apt_repos
tasks_from: add
vars:
apt_repo:
name: prosody
uris: "https://packages.prosody.im/debian"
suites: "{{ ansible_facts['distribution_release'] }}"
components:
- main
signed_by: /usr/share/keyrings/prosody-archive-keyring.gpg
when: preinstalled == false or preinstalled is not defined
- name: jitsimeet | add jitsi repository
deb822_repository:
name: jitsi-stable
types: deb
uris: "https://download.jitsi.org"
suites: "stable/"
signed_by: /usr/share/keyrings/jitsi-archive-keyring.gpg
notify: apt_update
include_role:
name: apt_repos
tasks_from: add
vars:
apt_repo:
name: jitsi-stable
uris: "https://download.jitsi.org"
suites: "stable/"
signed_by: /usr/share/keyrings/jitsi-archive-keyring.gpg
when: preinstalled == false or preinstalled is not defined
- name: jitsimeet | flush handlers
@@ -14,37 +14,34 @@
- { url: "https://dl.yarnpkg.com/debian/pubkey.gpg", localkey: "yarn-archive-keyring.gpg" }
- { url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key", localkey: "nodesource-archive-keyring.gpg" }
- name: mastodon | package manager | remove legacy repository files
file:
path: "/etc/apt/sources.list.d/{{ item }}.list"
state: absent
loop:
- yarn
- nodejs
- name: mastodon | package manager | add yarn repository
deb822_repository:
name: yarn
types: deb
uris: "https://dl.yarnpkg.com/debian"
suites: stable
components:
- main
signed_by: /usr/share/keyrings/yarn-archive-keyring.gpg
mode: "0644"
include_role:
name: apt_repos
tasks_from: add
vars:
apt_repo:
name: yarn
uris: "https://dl.yarnpkg.com/debian"
suites: stable
components:
- main
signed_by: /usr/share/keyrings/yarn-archive-keyring.gpg
- name: mastodon | package manager | add nodejs repository
deb822_repository:
name: nodejs
types:
- deb
- deb-src
uris: "https://deb.nodesource.com/node_{{ node_major_version }}.x"
suites: "{{ ansible_facts['distribution_release'] }}"
components:
- main
signed_by: /usr/share/keyrings/nodesource-archive-keyring.gpg
mode: "0644"
include_role:
name: apt_repos
tasks_from: add
vars:
apt_repo:
name: nodejs
types:
- deb
- deb-src
uris: "https://deb.nodesource.com/node_{{ node_major_version }}.x"
suites: "{{ ansible_facts['distribution_release'] }}"
components:
- main
signed_by: /usr/share/keyrings/nodesource-archive-keyring.gpg
- name: mastodon | package manager | remove legacy keyring files
file:
+14 -16
View File
@@ -31,23 +31,21 @@
creates: /usr/share/keyrings/mongodb-archive-keyring.gpg
# Hinweis: Der Pfad /usr/share/keyrings/ ist der empfohlene Ort für Schlüssel, die mit 'signed-by' verwendet werden.
- name: Remove legacy MongoDB repository file
ansible.builtin.file:
path: "/etc/apt/sources.list.d/mongodb-org-{{ omada_controller_mongodb_version }}.list"
state: absent
- name: Add MongoDB repository
ansible.builtin.deb822_repository:
name: "mongodb-org-{{ omada_controller_mongodb_version }}"
types: deb
uris: "https://repo.mongodb.org/apt/debian"
suites: "{{ omada_controller_mongodb_repo_release }}/mongodb-org/{{ omada_controller_mongodb_version }}"
components:
- main
architectures:
- amd64
- arm64
signed_by: /usr/share/keyrings/mongodb-archive-keyring.gpg
include_role:
name: apt_repos
tasks_from: add
vars:
apt_repo:
name: "mongodb-org-{{ omada_controller_mongodb_version }}"
uris: "https://repo.mongodb.org/apt/debian"
suites: "{{ omada_controller_mongodb_repo_release }}/mongodb-org/{{ omada_controller_mongodb_version }}"
components:
- main
architectures:
- amd64
- arm64
signed_by: /usr/share/keyrings/mongodb-archive-keyring.gpg
# Der 'signed-by'-Parameter verweist auf den zuvor dearmored Schlüssel.
- name: Install MongoDB server
@@ -15,20 +15,18 @@
dest: "/usr/share/keyrings/php-sury.gpg"
mode: '0644'
- name: webservers | nextcloud | prereq | remove legacy php repo file
ansible.builtin.file:
path: /etc/apt/sources.list.d/php-sury.list
state: absent
- name: webservers | nextcloud | prereq | add php repo
ansible.builtin.deb822_repository:
name: php-sury
types: deb
uris: "https://packages.sury.org/php/"
suites: "{{ ansible_facts['distribution_release'] | lower }}"
components:
- main
signed_by: /usr/share/keyrings/php-sury.gpg
include_role:
name: apt_repos
tasks_from: add
vars:
apt_repo:
name: php-sury
uris: "https://packages.sury.org/php/"
suites: "{{ ansible_facts['distribution_release'] | lower }}"
components:
- main
signed_by: /usr/share/keyrings/php-sury.gpg
- name: webservers | nextcloud | prereq | install php
ansible.builtin.apt: