Don’t do this! Turns out I was doing this wrong. The below code is only needed if you’ve got things wrong, and you should instead be using keep_vm = "on_success"
. The more you know, eh?
If you’ve got a command in your packer
script that looks like this:
provisioner "shell" {
inline = ["shutdown -h now"]
}
Try running this instead:
provisioner "shell" {
inline = [
"echo Provisioning complete. Shutting down.",
"(sleep 5 ; shutdown -h now) &"
]
}
This will force packer to execute a command which is pushed into the background, returning a return code (RC) of 0, which the system will interpret as a successful result. 5 seconds later the machine will shut itself down by itself.