Skip to content

Commit f161e24

Browse files
committed
devconfig: add automatic APT mirror fallback for Debian testing
Debian testing (trixie) VMs can fail to provision when configured APT mirrors become unavailable or unresponsive. This is particularly common with local or regional mirrors that may have intermittent connectivity issues. This fix adds automatic mirror health checking specifically for Debian testing systems. The implementation: 1. Extracts the currently configured APT mirror hostname 2. Tests connectivity to the mirror on port 80 with a 10 second timeout 3. Falls back to official Debian mirrors if the test fails 4. Backs up the original sources.list before making changes 5. Updates the APT cache after switching mirrors 6. Provides clear user notification about the fallback The check only runs on Debian testing systems where devconfig_debian_testing is set to true, avoiding any impact on stable Debian or other distributions. This ensures that Debian testing VMs can successfully provision even when the initially configured mirror is unavailable, improving reliability for development and testing workflows. Generated-by: Claude AI Signed-off-by: Luis Chamberlain <[email protected]>
1 parent d08ce54 commit f161e24

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
# Only run mirror checks for Debian testing (trixie) where mirror issues are common
3+
- name: Extract current APT mirror hostname
4+
shell: |
5+
grep -E "^deb\s+http" /etc/apt/sources.list | head -1 | awk '{print $2}' | sed 's|http://||' | cut -d'/' -f1
6+
register: apt_mirror_host
7+
changed_when: false
8+
ignore_errors: yes
9+
10+
- name: Check connectivity to current APT mirror
11+
wait_for:
12+
host: "{{ apt_mirror_host.stdout }}"
13+
port: 80
14+
timeout: 10
15+
register: mirror_connectivity
16+
ignore_errors: yes
17+
when: apt_mirror_host.stdout != ""
18+
19+
- name: Display mirror check results
20+
debug:
21+
msg: |
22+
Current APT mirror: {{ apt_mirror_host.stdout | default('Not found') }}
23+
Mirror connectivity: {{ 'OK' if mirror_connectivity is not failed else 'FAILED' }}
24+
when: apt_mirror_host.stdout != ""
25+
26+
- name: Fall back to official Debian mirrors if current mirror fails
27+
block:
28+
- name: Backup current sources.list
29+
copy:
30+
src: /etc/apt/sources.list
31+
dest: /etc/apt/sources.list.backup
32+
remote_src: yes
33+
become: yes
34+
35+
- name: Apply Debian testing fallback sources
36+
template:
37+
src: debian-testing-fallback-sources.list
38+
dest: /etc/apt/sources.list
39+
owner: root
40+
group: root
41+
mode: '0644'
42+
become: yes
43+
44+
- name: Update APT cache after mirror change
45+
apt:
46+
update_cache: yes
47+
cache_valid_time: 0
48+
become: yes
49+
50+
- name: Inform user about mirror fallback
51+
debug:
52+
msg: |
53+
WARNING: The configured APT mirror '{{ apt_mirror_host.stdout }}' is not accessible.
54+
Falling back to official Debian testing mirrors:
55+
- deb.debian.org for main packages
56+
- security.debian.org for security updates
57+
58+
This may result in slower package downloads depending on your location.
59+
Consider configuring a local mirror for better performance.
60+
61+
when:
62+
- apt_mirror_host.stdout != ""
63+
- mirror_connectivity is failed

playbooks/roles/devconfig/tasks/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
tags: hostname
3131

3232
# Distro specific
33+
34+
# Check and fix APT mirrors for Debian testing before installing dependencies
35+
- name: Check and fix APT mirrors for Debian testing
36+
include_tasks: check-apt-mirrors.yml
37+
when:
38+
- devconfig_debian_testing is defined
39+
- devconfig_debian_testing | bool
40+
3341
- name: Install dependencies
3442
ansible.builtin.include_tasks: install-deps/main.yml
3543
tags: ['vars', 'vars_simple']
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
deb http://deb.debian.org/debian testing main contrib non-free non-free-firmware
2+
deb-src http://deb.debian.org/debian testing main contrib non-free non-free-firmware
3+
4+
# Security updates
5+
deb http://security.debian.org/debian-security testing-security main contrib non-free non-free-firmware
6+
deb-src http://security.debian.org/debian-security testing-security main contrib non-free non-free-firmware
7+
8+
# Updates (if available for testing)
9+
deb http://deb.debian.org/debian testing-updates main contrib non-free non-free-firmware
10+
deb-src http://deb.debian.org/debian testing-updates main contrib non-free non-free-firmware

0 commit comments

Comments
 (0)