4

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.

kojiro
  • 559
  • 3
  • 8
  • 25

1 Answers1

1

Welp, I found the answer. It doesn't have much to do with Packer or Puppet. It turns out that Vagrant caches boxes somewhere. After my first install, Vagrant was always using the same old box, and ignoring any updates from newer packer builds. To fix this (until I figure out how to version packer-built vagrant boxes) I can destroy the box each time with

vagrant box remove packer_virtualbox-iso_virtualbox.box
kojiro
  • 559
  • 3
  • 8
  • 25