Packer Vagrant builder - confused about Vagrant template option

Versions I am using:

  • Vagrant 2.2.14
  • Packer v1.7.0

I could be misreading the documentation, but packer vagrant builder options I tried so far did not end up in producing desired result. All I am after is to have my custom Vagrantfile embedded into produced box.

I need it for obvious reasons to control some of the networking options. I could mandate for users to manually copy Vagrantfile before doing vagrant up, but the issue is I can’t rely on users following the process, so I’d like to enforce it at the box init by default.

I tried to use vagrant builder’s options below:
Vagrant - Builders | Packer by HashiCorp and Vagrant - Builders | Packer by HashiCorp but none of them achieved desired result. At vagrant init default Vagrantfile is still populated.

1 Like

I came across this post - virtualbox - Packaging a base box with a custom Vagrantfile - Stack Overflow referencing config load order.

Packer template I am using:

{
    "builders": [{
        "communicator": "ssh",
        "source_path": "analysis",
        "provider": "vmware_desktop",
        "skip_add": true,
        "add_force": true,
        "type": "vagrant",
        "output_vagrantfile": "Vagrantfile.template"
    }],
    "provisioners": [
      {
        "type": "shell",
          "scripts": [
            "./scripts/homebrew-install.sh"
          ]
      },
      {
        "type": "ansible",
          "playbook_file": "./osx-analysis-playbook/main.yml",
          "user": "vagrant",
          "extra_arguments": [
            "--extra-vars",
            "ansible_python_interpreter=/usr/bin/python"
          ]
      },
        {
            "type": "shell",
            "execute_command": "echo 'vagrant' | {{.Vars}} sudo -ES {{.Path}}",
            "scripts": [
                "scripts/post-cleanup.sh"
            ]
        }
    ]
}

I noticed after adding produced box there’s a file ~/.vagrant.d/boxes/analysis/0/vmware_desktop/include/_Vagrantfile that contains my custom config, but when I do vagrant init analysis && vagrant up I don’t see anything being merged and environment is initialized with default Vagrantfile resulting in undesired networking config.

1 Like

Did you resolve it?
I have the same issue right now.

[update]

I solved it.
My vagrant up was giving me an error.