How to package files with a Vagrant box?

2019-04-07 09:39发布

问题:

So I created a Vagrant box with the following command:

vagrant package --base box_name_here --vagrantfile Vagrantfile --include manifests/

manifests/ is a directory with a puppet manifest and some subdirectories with some files used during the provisioning process. Puppet is called in the Vagrantfile like so:

config.vm.provision :puppet do |puppet|
    puppet.manifests_path = "manifests"
    puppet.manifest_file  = "web-dev.pp"
end

When I explore the packaged .box archive Vagrant creates, I see the folder located at box_name_here.box/includes/manifests. However, vagrant up dies with the following error when I try to run it:

The manifests path specified for Puppet does not exist: c:/vagrant/manifests

Are the files somewhere else?

I saw this post: https://github.com/mitchellh/vagrant/issues/344

But the answer is a bit opaque; I don't quite know how to translate the modulepath response to my manifests_path problem.

I altered the vagrantfile so that the line reads

puppet.manifests_path = "./manifests"

...but that did not correct the problem. I still get the same error message.

回答1:

After some experimentation, the incredibly obvious answer is:

puppet.manifests_path = File.expand_path("../manifests", __FILE__)