I decided to learn Packer by putting together a FreeBSD Vagrant box. The whole setup is on GitHub. Everything works well until the post-processing stage. Actually, that stage likewise claims to complete without error, but when I try to launch a Vagrant box the virtual machine doesn't have any of the effects that were supposed to have been done by Puppet.
Specifically, if I run packer build freebsd.json
in a clone of the repo I end up with an ovf and vmdk file that I can import in VirtualBox and get an instance with a vagrant
user and the .ssh setup described below.
But I also get a packer_virtualbox-iso_virtualbox.box
file, and if I do
vagrant init packer_virtualbox-iso_virtualbox.box
vagrant up
I get an instance that boots and has pkg and puppet installed, but does not have the vagrant
user or its home directory. Here's a trimmed version of the packer json file:
{
"builders": [SNIP],
"provisioners": [{
"type": "shell",
"script": "install-puppet",
"execute_command": "chmod +x {{ .Path }}; env {{ .Vars }} {{ .Path }}"
}, {
"type": "puppet-masterless",
"manifest_file": "site.pp",
"execute_command": "cd {{.WorkingDir}} && env {{.FacterVars}} puppet apply --verbose --modulepath='{{.ModulePath}}' {{if ne .HieraConfigPath \"\"}}--hiera_config='{{.HieraConfigPath}}' {{end}} {{if ne .ManifestDir \"\"}}--manifestdir='{{.ManifestDir}}' {{end}} --detailed-exitcodes {{.ManifestFile}}"
}],
"post-processors": [{
"type": "compress",
"compression_level": 9,
"keep_input_artifact": true,
"output": "archive.tar.bz2"
}, {
"type": "vagrant",
"compression_level": 9,
"keep_input_artifact": true
}]
}
It's as if the Vagrant box is somehow rolling back to the point where the first provisioner has run, but the second has not. What can explain it?
Update
I tried running packer in debug mode by exporting PACKER_LOG=debug
and noticed this in the output, relevant to the Puppet part:
2015/12/16 20:48:12 packer-builder-virtualbox-iso: 2015/12/16 20:48:12 remote command exited with '2': cd /tmp/packer-puppet-masterless && env FACTER_packer_build_name='virtualbox-iso' FACTER_packer_builder_type='virtualbox-iso' puppet apply --verbose --modulepath='' --detailed-exitcodes /tmp/packer-puppet-masterless/manifests/site.pp
2015/12/16 20:48:12 packer-builder-virtualbox-iso: 2015/12/16 20:48:12 [INFO] RPC endpoint: Communicator ended with: 2
2015/12/16 20:48:12 [INFO] 539 bytes written for 'stdout'
2015/12/16 20:48:12 [INFO] 0 bytes written for 'stderr'
2015/12/16 20:48:12 [INFO] RPC client: Communicator ended with: 2
2015/12/16 20:48:12 [INFO] RPC endpoint: Communicator ended with: 2
2015/12/16 20:48:12 packer-provisioner-puppet-masterless: 2015/12/16 20:48:12 [INFO] 0 bytes written for 'stderr'
2015/12/16 20:48:12 packer-provisioner-puppet-masterless: 2015/12/16 20:48:12 [INFO] 539 bytes written for 'stdout'
2015/12/16 20:48:12 packer-provisioner-puppet-masterless: 2015/12/16 20:48:12 [INFO] RPC client: Communicator ended with: 2
I don't know if this is the main cause or not, but I tried another run with the execute_command
ending with true
. It changed the log output, (no more "Communicator ended with: 2") but did not change the outcome.