Packer and Ansible and Virtualbox, Oh My!
I routinely build Vagrant boxes in the background while working on another tasks. Packer is an amazing tool that makes this process so much faster and a hell of a lot easier.
Ansible makes provisioning so much easier and faster. When you couple that with Packer, you have a near perfect process for building Vagrant boxes that can be fully automated.
However, there is one small issue, or two, maybe three, maybe more than that.
But don't get me wrong. Packer and Ansible are still both great tools and I love them and continue to use them. There are just times when you need to take these lemons and turn them into lemonade. After spending a little bit of time trying to figure out what is going on, I decided to try something different.
I switched from the ansible-remote
provisioner to the ansible-local
provisioner. We were installing Ansible on our Vagrant boxes anyway. After tweaking the files to run with ansible-local
and attempting to build the box again the Ansible hanging issues disappeared.
What I can gather, the way Packer sets up the SSH connections with the VM (we've had it happen the most with VirtualBox) and Ansible to use, after a while it just dies but no errors are thrown, maybe a "timeout waiting for privilege escalation prompt" error which makes no sense, since re-running with the exact same settings had that same error happen further into the playbook.
Then there's the Ansible-specific issues that popup every now and then where you have no idea if it's Ansible, Packer or both, but downgrading Ansible seems to fix it: