Skip to content

Commit 60d20f0

Browse files
committed
base_image: force SELinux relabeling for Fedora on Debian hosts
Fedora guest images created on Debian hosts fail to boot with exit code 127 errors because the filesystem lacks proper SELinux contexts. All files have unlabeled_t context causing SELinux to block all binary execution. virt-builder's --selinux-relabel flag is a no-op compatibility option. While virt-builder attempts automatic relabeling, it fails silently on non-SELinux hosts and falls back to creating /.autorelabel, which triggers a chicken-and-egg problem where the relabeling service itself cannot execute. Add a post-processing step that runs virt-customize --selinux-relabel after virt-builder creates the image. This runs only when building Fedora guests on Debian hosts, ensuring proper SELinux contexts before first boot. virt-customize has the actual working implementation of SELinux relabeling. Generated-by: Claude AI Signed-off-by: Daniel Gomez <[email protected]>
1 parent 88f94e7 commit 60d20f0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

playbooks/roles/base_image/tasks/base-image.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
creates: "{{ base_image_pathname }}"
5353
when:
5454
- libvirt_uri_system|bool
55+
register: virt_builder_result
5556

5657
- name: Generate a new base image for {{ base_image_os_version }}
5758
ansible.builtin.command:
@@ -71,6 +72,37 @@
7172
creates: "{{ base_image_pathname }}"
7273
when:
7374
- not libvirt_uri_system|bool
75+
register: virt_builder_result
76+
77+
- name: Force SELinux relabeling for Fedora images on non-SELinux hosts
78+
become: true
79+
become_method: ansible.builtin.sudo
80+
ansible.builtin.command:
81+
argv:
82+
- "virt-customize"
83+
- "-a"
84+
- "{{ base_image_pathname }}"
85+
- "--selinux-relabel"
86+
when:
87+
- libvirt_uri_system|bool
88+
- guestfs_fedora is defined
89+
- guestfs_fedora|bool
90+
- ansible_facts['os_family']|lower == 'debian'
91+
- virt_builder_result is changed
92+
93+
- name: Force SELinux relabeling for Fedora images on non-SELinux hosts
94+
ansible.builtin.command:
95+
argv:
96+
- "virt-customize"
97+
- "-a"
98+
- "{{ base_image_pathname }}"
99+
- "--selinux-relabel"
100+
when:
101+
- not libvirt_uri_system|bool
102+
- guestfs_fedora is defined
103+
- guestfs_fedora|bool
104+
- ansible_facts['os_family']|lower == 'debian'
105+
- virt_builder_result is changed
74106

75107
- name: Set proper ownership on base image for rcloud access (system libvirt)
76108
become: true

0 commit comments

Comments
 (0)