Troubleshooting failed packer build

I am just getting started with Packer, and have had several instances where my build is failing and I'd LOVE to log in to the box to investigate the cause. However, there doesn't seem to be a packer login or similar command to give me a shell. Instead, the run just terminates and tears down the box before I have a chance to investigate.

I know I can use the --debug flag to pause execution at each stage, but I'm curios if there is a way to just pause after a failed run (and prior to cleanup) and then runt he cleanup after my debugging is complete.



Having used Packer extensively, the --debug flag is most helpful. Once the process is paused you SSH to the box with the key (in the current dir) and figure out what is going on.

Yeah, the way I handle this is to put a long sleep in a script inline provisioner after the failing step, then I can ssh onto the box and see what's up. Certainly the debug flag is useful, but if you're running the packer build remotely (I do it on jenkins) you can't really sit there and hit the button.

I do try and run tests on all the stuff I'm packing outside of the build - using the Chef provisioner I've got kitchen tests all over everything before it gets packed. It's a royal pain to try and debug anything besides packer during a packer run.

This was my top annoyance with packer. Thankfully, packer build now has an option -on-error that gives you options.

packer build -on-error=ask ... to the rescue.

From the packer build docs:

-on-error=cleanup (default), -on-error=abort, -on-error=ask - Selects what to do when the build fails. cleanup cleans up after the previous steps, deleting temporary files and virtual machines. abort exits without any cleanup, which might require the next build to use -force. ask presents a prompt and waits for you to decide to clean up, abort, or retry the failed step.

While looking up info for this myself, I ran across numerous bug reports/feature requests for Packer.

Apparently, someone added new features to the virtualbox and vmware builders a year ago (), but it hasn't gotten merged into main.

In another bug (), they were looking at adding additional features to --debug, but that seemed to stall out.

If a Packer build is failing, first check where the build process has got stuck, but do the check in this sequence:

  1. Are the boot commands the appropriate ones?
  2. Is the preseed config OK?
  3. If 1. and 2. are OK, then it means box has booted and the next to check is the login: SSH keys, ports, ...
  4. Finally any issues within the provisioning scripts


 ? Packer failing after terminating source with non-zero exit status: 2
 ? How to Configure Packer to Run 'sudo' to Provision Digital Ocean Image?
 ? Install packages in Ansible conditionally
 ? Packer and Ansible SSH/Sudo
 ? Can I use one packer builder with many provisioners and still run parallel builds?
 ? ami_block_device_mappings not working properly with packer
 ? Copy local file to remote AWS EC2 instance with Ansible
 ? Ansible handler using if statements
 ? In jenkins what will be my Playbook path ? how to set up Inventory there are 3 option for the same
 ? No IP information in hostvars