Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a custom Vagrantfile from Packer

I've been trying to figure out how to create a custom vagrant file from packer, I understand that in the post-processor section you will define a directory from which to scrap from, what I do not understand is if there needs to be a specifically named file inside as to which to gather data from.

"post-processors": [{
  "vagrantfile_template": "configs/vagrantfile_template",
  "type": "vagrant"
}],

The above code to my knowledge would look under configs/vagrantfile_template, but what would need to be in here? Would I create a Vagrantfile and place it there, or would it need to be a specifically named Ruby file?

like image 728
ehime Avatar asked Nov 23 '25 07:11

ehime


1 Answers

The vagrantfile_template option in a vagrant post-processor points directly to a file and not a directory [0]. The contents of this file should be structured like a normal Vagrantfile and contain any customizations for the box artifact that you are creating.

For example, if you wanted users of your custom Vagrant box to not have the /vagrant shared folder mounted by default, your Vagrantfile template might look like this...

Vagrant.configure("2") do |config|
  config.vm.synced_folder \
    ".",
    "/vagrant",
    :disabled => true
end

Resources

  • [0]: https://github.com/mitchellh/packer/blob/53b1db16692c7bf2e654ac125b8676c02154d07a/post-processor/vagrant/post-processor.go#L113-L138
like image 63
cookrn Avatar answered Nov 28 '25 17:11

cookrn