Files
ansible-playbooks/roles/os-updates/tasks/update_mirrors.yml
T
2026-05-08 21:27:10 +02:00

66 lines
2.3 KiB
YAML

- name: Run last dist upgrade before changing codename
apt:
update_cache: yes
upgrade: dist
when: ansible_facts['distribution_release'] != os_update_version_codename
- name: Backup existing sources.list
copy:
src: /etc/apt/sources.list
dest: /etc/apt/sources.list.bak
remote_src: yes
force: yes
ignore_errors: true
when: ansible_facts['distribution_version'] is version('13', '<=') # Only apply under Debian 13 and newer
- name: Remove existing sources.list to avoid conflicts with new deb822 format
file:
path: /etc/apt/sources.list
state: absent
when: ansible_facts['distribution_version'] is version('13', '>=') # Only apply for Debian 13 and newer
- name: Update sources.list.d with new mirrors
template:
src: sources.list-deb822.j2
dest: /etc/apt/sources.list.d/debian.sources
when: ansible_facts['distribution_version'] is version('13', '>=') # Only apply for Debian 13 and newer
register: cache_update_needed
- name: Update sources.list with new mirrors for older Debian versions
template:
src: sources.list.j2
dest: /etc/apt/sources.list
when: ansible_facts['distribution_version'] is version('13', '<') # Only apply for Debian versions older than 13
register: cache_update_needed
- name: Find sources list fragments
find:
paths: /etc/apt/sources.list.d
patterns: "*.list,*.sources"
file_type: file
register: apt_sources_list_fragments
- name: Align suite codenames in sources.list.d for .list files
replace:
path: "{{ item.path }}"
backup: yes
regexp: '^(deb(?:-src)?\s+(?:\[[^\]]+\]\s+)?\S+\s+)({{ os_update_debian_codenames | join("|") }})(-[^\s]+)?(\s+.+)$'
replace: '\1{{ os_update_version_codename }}\3\4'
loop: "{{ apt_sources_list_fragments.files }}"
when: (item.path | regex_search('\.list$')) is not none
register: cache_update_needed
- name: Align suite codenames in sources.list.d for .sources files
replace:
path: "{{ item.path }}"
backup: yes
regexp: '^(Suites:\s+)({{ os_update_debian_codenames | join("|") }})(-[^\s]+)?(.*)$'
replace: '\1{{ os_update_version_codename }}\3\4'
loop: "{{ apt_sources_list_fragments.files }}"
when: (item.path | regex_search('\.sources$')) is not none
register: cache_update_needed
- name: Update apt cache
apt:
update_cache: yes
when: cache_update_needed is changed