Skip to content

Commit 5d6b951

Browse files
committed
base_image: apply virt-builder template to custom images
Custom images were bypassing the virt-builder template entirely, missing essential customizations like kdevops user creation and SSH service configuration. This caused virt-sysprep SSH injection to fail with "user kdevops does not exist on the guest". Add virt-customize step to apply the same virt-builder.j2 template to custom images after download, ensuring they get: - kdevops user creation with proper UID - SSH service configuration (stop/reconfigure/start) - sudo permissions setup - All other template customizations The customization is only applied once when the sentinel file doesn't exist, avoiding redundant processing on subsequent runs. Generated-by: Claude AI Signed-off-by: Daniel Gomez <[email protected]>
1 parent 23c9cad commit 5d6b951

File tree

4 files changed

+92
-14
lines changed

4 files changed

+92
-14
lines changed

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,78 @@
8585
chdir: "{{ custom_image_dir }}"
8686
changed_when: false
8787

88+
- name: Get the UID of the kdevops user on the control host
89+
ansible.builtin.command:
90+
cmd: "id -u kdevops"
91+
register: id_output
92+
changed_when: false
93+
failed_when: false
94+
when:
95+
- not sentinel_stat.stat.exists
96+
97+
- name: Set the kdevops UID for custom image
98+
ansible.builtin.set_fact:
99+
kdevops_uid: "-u {{ id_output.stdout }}"
100+
when:
101+
- not sentinel_stat.stat.exists
102+
- id_output.rc == 0
103+
104+
- name: Set default kdevops UID for custom image if user doesn't exist
105+
ansible.builtin.set_fact:
106+
kdevops_uid: ""
107+
when:
108+
- not sentinel_stat.stat.exists
109+
- id_output.rc != 0
110+
111+
- name: Create a temporary file for virt-customize commands
112+
ansible.builtin.tempfile:
113+
state: file
114+
register: custom_command_file
115+
when:
116+
- not sentinel_stat.stat.exists
117+
118+
- name: Construct the virt-customize command file for custom image
119+
ansible.builtin.template:
120+
src: "{{ role_path }}/templates/virt-builder.j2"
121+
dest: "{{ custom_command_file.path }}"
122+
mode: "u=rw"
123+
when:
124+
- not sentinel_stat.stat.exists
125+
126+
- name: Customize the downloaded image with kdevops user and settings
127+
become: true
128+
become_method: ansible.builtin.sudo
129+
ansible.builtin.command:
130+
argv:
131+
- "virt-customize"
132+
- "-a"
133+
- "{{ custom_image }}"
134+
- "--commands-from-file"
135+
- "{{ custom_command_file.path }}"
136+
when:
137+
- libvirt_uri_system|bool
138+
- not sentinel_stat.stat.exists
139+
140+
- name: Customize the downloaded image with kdevops user and settings (non-root)
141+
ansible.builtin.command:
142+
argv:
143+
- "virt-customize"
144+
- "-a"
145+
- "{{ custom_image }}"
146+
- "--commands-from-file"
147+
- "{{ custom_command_file.path }}"
148+
when:
149+
- not libvirt_uri_system|bool
150+
- not sentinel_stat.stat.exists
151+
152+
- name: Clean up the virt-customize command file
153+
ansible.builtin.file:
154+
path: "{{ custom_command_file.path }}"
155+
state: absent
156+
when:
157+
- custom_command_file.path is defined
158+
- not sentinel_stat.stat.exists
159+
88160
- name: Touch the custom image sentinel
89161
ansible.builtin.file:
90162
path: "{{ custom_image_ok }}"

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@
5858
- "{{ root_image }}"
5959
- "--hostname"
6060
- "{{ inventory_hostname }}"
61-
- "--run-command"
62-
- "useradd -s /bin/bash -m kdevops || true"
63-
- "--run-command"
64-
- "echo 'kdevops ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/kdevops"
65-
- "--password"
66-
- "kdevops:password:kdevops"
6761
- "--ssh-inject"
6862
- "kdevops:file:{{ ssh_key }}.pub"
6963
- "--timezone"
@@ -79,12 +73,6 @@
7973
- "{{ root_image }}"
8074
- "--hostname"
8175
- "{{ inventory_hostname }}"
82-
- "--run-command"
83-
- "useradd -s /bin/bash -m kdevops || true"
84-
- "--run-command"
85-
- "echo 'kdevops ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/kdevops"
86-
- "--password"
87-
- "kdevops:password:kdevops"
8876
- "--ssh-inject"
8977
- "kdevops:file:{{ ssh_key }}.pub"
9078
- "--timezone"

playbooks/roles/guestfs/tasks/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131
- bringup
3232
ansible.builtin.set_fact:
3333
base_image: "{{ storagedir }}/base_images/{{ virtbuilder_os_version }}.raw"
34+
when:
35+
- not guestfs_has_custom_raw_image|bool
36+
delegate_to: localhost
37+
38+
- name: Set the pathname of the custom OS base image
39+
tags:
40+
- base_image
41+
- bringup
42+
ansible.builtin.set_fact:
43+
base_image: "{{ storagedir }}/custom_images/{{ virtbuilder_os_version }}/{{ virtbuilder_os_version }}.raw"
44+
when:
45+
- guestfs_has_custom_raw_image|bool
3446
delegate_to: localhost
3547

3648
- name: Ensure the required base OS image exists

playbooks/roles/monitoring/files/plot_migration_stats.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ def plot_folio_migration(stats_files, output_file):
155155

156156
# Different line styles for baseline vs dev
157157
if is_dev:
158-
linestyle = (0, (5, 3)) # Custom dash pattern: 5 points on, 3 points off
158+
linestyle = (
159+
0,
160+
(5, 3),
161+
) # Custom dash pattern: 5 points on, 3 points off
159162
linewidth = 2.3
160163
alpha = 0.9
161164
else:
@@ -167,7 +170,10 @@ def plot_folio_migration(stats_files, output_file):
167170
color = color_map.get(name, plt.cm.tab10(idx % 10))
168171

169172
if is_dev:
170-
linestyle = (0, (5, 3)) # Custom dash pattern: 5 points on, 3 points off
173+
linestyle = (
174+
0,
175+
(5, 3),
176+
) # Custom dash pattern: 5 points on, 3 points off
171177
linewidth = 2.3
172178
alpha = 0.9
173179
else:

0 commit comments

Comments
 (0)