Skip to content

Commit 7d2ce95

Browse files
committed
devconfig: enhance hop1 detection to support traditional sources.list
Enhance the hop1 mirror detection to work with both DEB822 and traditional sources.list formats. When a hop1 mirror is detected on the control host (regardless of format) and the guest is running Debian testing, automatically convert to DEB822 format for consistency and modern package management. Key improvements: - Detect hop1 servers from both /etc/apt/sources.list.d/debian.sources (DEB822) and /etc/apt/sources.list (traditional format) - Extract mirror host and path correctly from both formats - Automatically convert Debian testing guests to use DEB822 when a hop1 mirror is available and accessible - Preserve the mirror path (e.g., /debian, /debian-mirror) from the control host configuration - Add connectivity checks before using the hop1 mirror - Fall back to official Debian mirrors only if hop1 is unavailable or inaccessible This ensures that local hop1 mirrors are used efficiently even when the control host hasn't migrated to DEB822 format yet, while modernizing the guest configuration for Debian testing systems. Generated-by: Claude AI Signed-off-by: Luis Chamberlain <[email protected]>
1 parent ab21aba commit 7d2ce95

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

playbooks/roles/devconfig/tasks/check-apt-mirrors.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
---
22
# Only run mirror checks for Debian testing (trixie) where mirror issues are common
3+
- name: Check hop count on control host
4+
delegate_to: localhost
5+
shell: |
6+
{{ topdir_path }}/scripts/get-distro-has-hop-count-sources.sh 1
7+
register: localhost_hop_count
8+
changed_when: false
9+
ignore_errors: yes
10+
11+
- name: Extract hop1 mirror info from control host (DEB822 format)
12+
delegate_to: localhost
13+
shell: |
14+
if [ -f /etc/apt/sources.list.d/debian.sources ]; then
15+
HOST=$(grep -E "^URIs:" /etc/apt/sources.list.d/debian.sources | head -1 | awk '{print $2}' | sed -E 's|https?://||')
16+
echo "${HOST}"
17+
fi
18+
register: localhost_hop1_mirror_deb822
19+
changed_when: false
20+
ignore_errors: yes
21+
when: localhost_hop_count.stdout == 'y'
22+
23+
- name: Extract hop1 mirror info from control host (legacy format)
24+
delegate_to: localhost
25+
shell: |
26+
if [ -f /etc/apt/sources.list ] && [ ! -f /etc/apt/sources.list.d/debian.sources ]; then
27+
LINE=$(grep -v "^#" /etc/apt/sources.list | grep -E "^deb\s+http" | head -1)
28+
if [ -n "$LINE" ]; then
29+
URL=$(echo $LINE | awk '{print $2}')
30+
echo "${URL}" | sed 's|http://||'
31+
fi
32+
fi
33+
register: localhost_hop1_mirror_legacy
34+
changed_when: false
35+
ignore_errors: yes
36+
when: localhost_hop_count.stdout == 'y'
37+
38+
- name: Set hop1 mirror variables
39+
set_fact:
40+
has_hop1_mirror: "{{ localhost_hop_count.stdout == 'y' }}"
41+
hop1_mirror_full: "{{ localhost_hop1_mirror_deb822.stdout if localhost_hop1_mirror_deb822.stdout != '' else localhost_hop1_mirror_legacy.stdout }}"
42+
when: localhost_hop_count.stdout == 'y'
43+
44+
- name: Parse hop1 mirror host and path
45+
set_fact:
46+
hop1_mirror_host: "{{ hop1_mirror_full.split('/')[0] }}"
47+
hop1_mirror_path: "/{{ hop1_mirror_full.split('/', 1)[1] if '/' in hop1_mirror_full else 'debian' }}"
48+
when:
49+
- has_hop1_mirror is defined
50+
- has_hop1_mirror | bool
51+
- hop1_mirror_full != ''
52+
353
- name: Check for DEB822-style sources
454
stat:
555
path: /etc/apt/sources.list.d/debian.sources
@@ -42,6 +92,69 @@
4292
Mirror connectivity: {{ 'OK' if mirror_connectivity is not failed else 'FAILED' }}
4393
when: apt_mirror_host.stdout != ""
4494

95+
- name: Configure APT sources based on hop1 availability and debian testing
96+
block:
97+
- name: Check connectivity to hop1 mirror if available
98+
wait_for:
99+
host: "{{ hop1_mirror_host }}"
100+
port: 80
101+
timeout: 10
102+
register: hop1_mirror_connectivity
103+
ignore_errors: yes
104+
when:
105+
- has_hop1_mirror is defined
106+
- has_hop1_mirror | bool
107+
- hop1_mirror_host is defined
108+
109+
- name: Use hop1 mirror with DEB822 format for debian testing
110+
block:
111+
- name: Backup current sources
112+
copy:
113+
src: "{{ item }}"
114+
dest: "{{ item }}.backup"
115+
remote_src: yes
116+
become: yes
117+
loop:
118+
- /etc/apt/sources.list
119+
- /etc/apt/sources.list.d/debian.sources
120+
ignore_errors: yes
121+
122+
- name: Apply hop1 mirror configuration using DEB822 format
123+
template:
124+
src: debian-hop1-mirror.sources
125+
dest: /etc/apt/sources.list.d/debian.sources
126+
owner: root
127+
group: root
128+
mode: '0644'
129+
become: yes
130+
131+
- name: Remove legacy sources.list if migrating to DEB822
132+
file:
133+
path: /etc/apt/sources.list
134+
state: absent
135+
become: yes
136+
when: not deb822_sources.stat.exists
137+
138+
- name: Update APT cache with hop1 mirror
139+
apt:
140+
update_cache: yes
141+
cache_valid_time: 0
142+
become: yes
143+
144+
- name: Inform user about hop1 mirror usage
145+
debug:
146+
msg: |
147+
Using local hop1 mirror with DEB822 format:
148+
Mirror: {{ hop1_mirror_host }}{{ hop1_mirror_path }}
149+
150+
This provides faster package downloads from your local mirror.
151+
Sources have been converted to modern DEB822 format.
152+
when:
153+
- has_hop1_mirror is defined
154+
- has_hop1_mirror | bool
155+
- hop1_mirror_connectivity is not failed
156+
- hop1_mirror_host is defined
157+
45158
- name: Fall back to official Debian mirrors if current mirror fails
46159
block:
47160
- name: Backup current sources (DEB822 format)
@@ -97,3 +210,4 @@
97210
when:
98211
- apt_mirror_host.stdout != ""
99212
- mirror_connectivity is failed
213+
- not (has_hop1_mirror is defined and has_hop1_mirror | bool and hop1_mirror_connectivity is not failed)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Types: deb deb-src
2+
URIs: http://{{ hop1_mirror_host }}{{ hop1_mirror_path | default('/debian') }}
3+
Suites: testing testing-updates
4+
Components: main contrib non-free non-free-firmware
5+
Enabled: yes
6+
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
7+
8+
Types: deb deb-src
9+
URIs: https://security.debian.org/debian-security
10+
Suites: testing-security
11+
Components: main contrib non-free non-free-firmware
12+
Enabled: yes
13+
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

0 commit comments

Comments
 (0)