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