From f1cf12307dd58733b1feb24b3382279d8194ffa4 Mon Sep 17 00:00:00 2001 From: Jason Rayne Date: Tue, 15 Apr 2025 16:25:52 -0700 Subject: [PATCH] Improve systemd ordering for cloud-init-local to preserve /var mount When enrolling bare-metal overcloud nodes with Kayobe, I encountered an ordering issue that was seemingly caused by an insufficient dependency declaration. This resulted in /var (and critical data such as authorized_keys) being overwritten during provisioning. This commit updates the systemd override to explicitly ensure the full /var mount is present before cloud-init-local.service starts. --- .../post-install.d/95-jammy-cloud-init-fixup | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/elements/jammy-cloud-init-fixup/post-install.d/95-jammy-cloud-init-fixup b/elements/jammy-cloud-init-fixup/post-install.d/95-jammy-cloud-init-fixup index 425d68a..a634683 100755 --- a/elements/jammy-cloud-init-fixup/post-install.d/95-jammy-cloud-init-fixup +++ b/elements/jammy-cloud-init-fixup/post-install.d/95-jammy-cloud-init-fixup @@ -1,11 +1,32 @@ #!/bin/bash - +# Exit immediately if a command exits with a non-zero status (-e), +# treat unset variables as an error and exit immediately (-u), +# and ensure that a pipeline fails if any part fails (-o pipefail). set -euo pipefail -# Ensure that cloud-init-local requires /var/lib/cloud to be mounted -cat > /etc/systemd/system/cloud-init-local.service <"${OVERRIDE_FILE}" [Unit] +Requires=var.mount +After=var.mount RequiresMountsFor=/var/lib/cloud EOF -echo "Applied fixup for cloud-init-local" +# Ensure correct permissions +chmod 755 "${OVERRIDE_DIR}" +chmod 644 "${OVERRIDE_FILE}" + +# Display a message indicating that the override has been created +echo "Systemd override for cloud-init-local.service created successfully"