[PATCH 4/8] base_image: put a guard check before adding kdevops user

Luis Chamberlain <[email protected]> Fri, 17 Oct 2025 19:31:49 -0700
Newsgroups dev.linux.lists.kdevops
Message-ID <[email protected]>
Use getent to check for the kdevop user before trying to add it.
This will be useful for cloud image instances, which may already
have some customizations on it.

Signed-off-by: Luis Chamberlain <[email protected]>
---
 playbooks/roles/base_image/templates/virt-builder.j2 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/playbooks/roles/base_image/templates/virt-builder.j2 b/playbooks/roles/base_image/templates/virt-builder.j2
index 5e3e4cd8..c56eefae 100644
--- a/playbooks/roles/base_image/templates/virt-builder.j2
+++ b/playbooks/roles/base_image/templates/virt-builder.j2
@@ -21,7 +21,7 @@ delete /boot/*rescue*
 delete /boot/loader/entries/*rescue*
 {% endif %}
 
-run-command useradd {{ kdevops_uid }} -s /bin/bash -m kdevops
+run-command getent passwd kdevops || useradd {{ kdevops_uid }} -s /bin/bash -m kdevops
 append-line /etc/sudoers.d/kdevops:kdevops   ALL=(ALL)       NOPASSWD: ALL
 edit /etc/default/grub:s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"/
 run-command {{ update_grub_cmd }}
-- 
2.51.0