From 48495a7b6d0ed54c0e5f2ac401e2e528f6dfa0fa Mon Sep 17 00:00:00 2001 From: Tyler <71953103+fntyler@users.noreply.github.com> Date: Mon, 1 Jun 2026 18:07:07 -0400 Subject: [PATCH] fix(azure-marketplace): reset cloud-init state (#518) --- AzureMarketplace/marketplace-image.pkr.hcl | 3 +++ CommonMarketplace/scripts/90-cleanup.sh | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/AzureMarketplace/marketplace-image.pkr.hcl b/AzureMarketplace/marketplace-image.pkr.hcl index 6bda5d7..ef43c2a 100644 --- a/AzureMarketplace/marketplace-image.pkr.hcl +++ b/AzureMarketplace/marketplace-image.pkr.hcl @@ -206,6 +206,9 @@ build { "sudo tar -xzf /tmp/walinuxagent.tar.gz -C /opt/walinuxagent-src --strip-components=1", "cd /opt/walinuxagent-src && sudo python3 setup.py install --register-service", "sudo rm -f /tmp/walinuxagent.tar.gz", + # Force systemd to re-read units after setup.py modifies walinuxagent.service. + # The version systemd has loaded is outdated" on first boot. + "sudo systemctl daemon-reload", "sudo systemctl enable walinuxagent", "waagent --version", ] diff --git a/CommonMarketplace/scripts/90-cleanup.sh b/CommonMarketplace/scripts/90-cleanup.sh index 2343c27..975afac 100644 --- a/CommonMarketplace/scripts/90-cleanup.sh +++ b/CommonMarketplace/scripts/90-cleanup.sh @@ -78,5 +78,11 @@ done find /var/log -mtime -1 -type f -exec truncate -s 0 {} \; rm -rf /var/log/*.gz /var/log/*.[0-9] /var/log/*-???????? -rm -rf /var/lib/cloud/instances/* +# Reset cloud-init state for redeploy. `rm -rf /var/lib/cloud/instances/*` alone +# leaves the /var/lib/cloud/instance symlink dangling, which causes cloud-init +# to enter `degraded done` on the deployed VM's first boot +if command -v cloud-init >/dev/null 2>&1; then + cloud-init clean --logs --machine-id +fi +rm -rf /var/lib/cloud/instance /var/lib/cloud/instances/* /var/lib/cloud/data/* /var/lib/cloud/sem/* rm -f /root/.ssh/authorized_keys /home/ubuntu/.ssh/authorized_keys