Skip to content

Commit aab2890

Browse files
committed
guestfs: relabel root image after virt-sysprep for Fedora on Debian
virt-sysprep modifies files in the root image (hostname, SSH keys, timezone, etc) but those modified files don't get SELinux labels because virt-sysprep's auto-relabeling is disabled with --no-selinux-relabel to avoid the chicken-and-egg problem where relabeling fails on Debian hosts. The complete workflow is now: 1. virt-builder creates base image (no SELinux labels) 2. virt-customize --selinux-relabel on base image (correct labels) 3. cp base to root.raw (labels preserved) 4. virt-sysprep customizes root.raw with --no-selinux-relabel (modified files unlabeled) 5. virt-customize --selinux-relabel on root.raw (NEW STEP - fixes all labels) This ensures all files have correct SELinux contexts before boot, including files created or modified by virt-sysprep. The relabeling runs on localhost with proper conditions for Fedora guests on Debian/Ubuntu hosts. Generated-by: Claude AI Signed-off-by: Daniel Gomez <[email protected]>
1 parent 8787069 commit aab2890

File tree

1 file changed

+30
-0
lines changed
  • playbooks/roles/guestfs/tasks/bringup

1 file changed

+30
-0
lines changed

playbooks/roles/guestfs/tasks/bringup/main.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,36 @@
112112
when:
113113
- not libvirt_uri_system|bool
114114

115+
- name: Relabel root image after virt-sysprep for Fedora on Debian (as root)
116+
become: true
117+
become_method: ansible.builtin.sudo
118+
ansible.builtin.command:
119+
argv:
120+
- "virt-customize"
121+
- "-a"
122+
- "{{ root_image }}"
123+
- "--selinux-relabel"
124+
delegate_to: localhost
125+
when:
126+
- libvirt_uri_system|bool
127+
- guestfs_fedora is defined
128+
- guestfs_fedora|bool
129+
- ansible_distribution|lower in ['debian', 'ubuntu']
130+
131+
- name: Relabel root image after virt-sysprep for Fedora on Debian (non-root)
132+
ansible.builtin.command:
133+
argv:
134+
- "virt-customize"
135+
- "-a"
136+
- "{{ root_image }}"
137+
- "--selinux-relabel"
138+
delegate_to: localhost
139+
when:
140+
- not libvirt_uri_system|bool
141+
- guestfs_fedora is defined
142+
- guestfs_fedora|bool
143+
- ansible_distribution|lower in ['debian', 'ubuntu']
144+
115145
- name: Create largeio devices
116146
ansible.builtin.include_tasks:
117147
file: "{{ role_path }}/tasks/bringup/largeio.yml"

0 commit comments

Comments
 (0)