fix: Manage repositories

This commit is contained in:
pulsar89.5 2024-06-03 18:05:23 +02:00
parent c825925d7c
commit 028beb4ea0
8 changed files with 52 additions and 13 deletions

View File

@ -7,11 +7,24 @@ apt_distribution_sections: main
apt_repositories: []
# Exemple:
# - name: sid
# url: http://deb.debian.org/debian
# suites: sid
# components: main
# key_path: /usr/share/keyrings/debian-archive-keyring.gpg
# - name: incus
# key: https://pkgs.zabbly.com/key.asc
# url: https://pkgs.zabbly.com/incus/stable
# distribution_release: bookworm
# distribution_section: main
# suites: bookworm
# components: main
# key_url: https://pkgs.zabbly.com/key.asc
# key_path: /etc/apt/keyrings/incus.asc
apt_preferences: []
# Exemple:
# - filename: sid
# package: "*"
# pin: release n=sid
# priority: 100
apt_remove: []
apt_install: []

View File

@ -8,7 +8,6 @@
- name: Importer les tâches d'ajout de dépôts tiers
ansible.builtin.import_tasks:
file: repositories.yml
when: apt_repositories | length > 0
- name: Exécuter les handlers
meta: flush_handlers

View File

@ -3,10 +3,13 @@
- name: Télécharger la clef du dépôt
ansible.builtin.get_url:
url: "{{ item.key }}"
dest: "/etc/apt/keyrings/{{ item.name }}.asc"
url: "{{ item.key_url }}"
dest: "{{ item.key_path }}"
mode: u=rw,g=r,o=r
become: true
when:
- apt_repositories | length > 0
- item.get('key_url', '') | length > 0
loop: "{{ apt_repositories }}"
loop_control:
label: "{{ item.name }}"
@ -14,13 +17,28 @@
- name: Ajouter le dépôt
ansible.builtin.template:
src: repository.list.j2
dest: /etc/apt/sources.list.d/{{ item.name }}.list
src: repository.sources.j2
dest: /etc/apt/sources.list.d/{{ item.name }}.sources
owner: root
group: root
mode: u=rw,g=r,o=r
when: apt_repositories | length > 0
become: true
loop: "{{ apt_repositories }}"
loop_control:
label: "{{ item.name }}"
notify: Mettre à jour le cache
- name: Ajouter le fichier de priorité
ansible.builtin.template:
src: preferences.j2
dest: /etc/apt/preferences.d/{{ item.priority }}-{{ item.name }}
owner: root
group: root
mode: u=rw,g=r,o=r
when: apt_preferences | length > 0
become: true
loop: "{{ apt_preferences }}"
loop_control:
label: "{{ item.name }}"
notify: Mettre à jour le cache

View File

@ -1,6 +1,6 @@
# {{ ansible_managed }}
APT::Default-Release "{{ apt_distribution_release }}";
APT::Default-Release "stable";
APT::Install-Recommends "false";
APT::Install-Suggests "false";
APT::Get::Show-Versions "true";

View File

@ -3,7 +3,7 @@
{% if apt_distribution_release == "sid" %}
Types: deb
URIs: https://deb.debian.org/debian
Suites: {{ apt_distribution_release }} {{ apt_distribution_release }}-updates {{ apt_distribution_release }}-backports
Suites: {{ apt_distribution_release }}
Components: {{ apt_distribution_sections }}
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
{% else %}

5
templates/preferences.j2 Normal file
View File

@ -0,0 +1,5 @@
# {{ ansible_managed }}
Package: {{ item.package }}
Pin: {{ item.pin }}
Pin-Priority: {{ item.priority }}

View File

@ -1,3 +0,0 @@
# {{ ansible_managed }}
deb [signed-by=/etc/apt/keyrings/{{ item.name }}.asc] {{ item.url }} {{ item.distribution_release }} {{ item.distribution_section }}

View File

@ -0,0 +1,7 @@
# {{ ansible_managed }}
Types: deb
URIs: {{ item.url }}
Suites: {{ item.suites }}
Components: {{ item.components }}
Signed-By: {{ item.key_path }}