canonical / canonical/cloud-init

Rebooting VM during packer build causes cloud-init to run instance modules again

Open
#4,359 15 comments 0 reactions 0 assignees View on GitHub
bug incomplete
Dominant language
Python
Stars
3.8k
Forks
1.1k
Avg merge
2d 23h
Merged PRs (30d)
18

Description

# Bug report
I am attempting to use Packer to create a golden image that mounts /var as a partition. In the Packer build data is copied from several folders to the mounted *alt_* folders and then a sed command is executed against fstab to replace the /alt_ with a blank to make the real mount points. The VM is then rebooted before continuing with the rest of the golden image configuration, however after the boot the changes made to fstab are replace by cloud-init. Log files are attached.

Packer build section
```
build {
sources = ["source.azure-arm.linux-image"]

provisioner "file" {
source = "${local.scripts_folder}/100_golden.cfg"
destination = "/tmp/"
}

provisioner "shell" {
inline = ["sudo mv /tmp/100_golden.cfg /etc/cloud/cloud.cfg.d/"]
}

# copy var to /alt_var
provisioner "shell" {
inline = [
"sudo sh -c 'cd /var/; tar cf - . | (cd /alt_var; tar xf -)'",
"sudo sh -c 'cd /home/; tar cf - . | (cd /alt_home; tar xf -)'",
"sudo sh -c 'cd /tmp/; tar cf - . | (cd /alt_tmp; tar xf -)'"
]
}

# reboot vm to mount /var
provisioner "shell" {
inline = [
"sudo sed -i 's#/alt_#/#' /etc/fstab",
]
}

# reboot vm to mount /var
provisioner "shell" {
inline = [
"sudo reboot"
]
expect_disconnect = true
pause_after = "60s"
}
}
```

Cloud Config
```
#cloud-config

disk_setup:
/dev/disk/azure/scsi1/lun0:
table_type: gpt
layout:
- 15
- 14
- 28
- 14
- 14
- 14
overwrite: True

fs_setup:
- device: /dev/disk/azure/scsi1/lun0
partition: 1
filesystem: ext4
- device: /dev/disk/azure/scsi1/lun0
partition: 2
filesystem: ext4
- device: /dev/disk/azure/scsi1/lun0
partition: 3
filesystem: ext4
- device: /dev/disk/azure/scsi1/lun0
partition: 4
filesystem: ext4
- device: /dev/disk/azure/scsi1/lun0
partition: 5
filesystem: ext4
- device: /dev/disk/azure/scsi1/lun0
partition: 6
filesystem: ext4

mounts:
- [ "/dev/disk/azure/scsi1/lun0-part1", "/alt_home", "auto", "defaults,nofail", "0", "2" ]
- [ "/dev/disk/azure/scsi1/lun0-part2", "/alt_tmp", "auto", "defaults,nofail", "0", "2" ]
- [ "/dev/disk/azure/scsi1/lun0-part3", "/alt_var", "auto", "defaults,nofail", "0", "2" ]
- [ "/dev/disk/azure/scsi1/lun0-part4", "/alt_var/log", "auto", "defaults,nofail,x-mount.mkdir", "0", "2" ]
- [ "/dev/disk/azure/scsi1/lun0-part5", "/alt_var/log/audit", "auto", "defaults,nofail,x-mount.mkdir", "0", "2" ]
- [ "/dev/disk/azure/scsi1/lun0-part6", "/alt_var/tmp", "auto", "defaults,nofail,x-mount.mkdir", "0", "2" ]
```
## Steps to reproduce the problem

## Environment details
- Cloud-init version:
/usr/bin/cloud-init 23.2.2-0ubuntu0~20.04.1
- Operating System Distribution:
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
- Cloud provider, platform or installer type:
Azure

## cloud-init logs
[cloud-init.tar.gz](https://github.com/canonical/cloud-init/files/12362093/cloud-init.tar.gz)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.