Zsolt Takács (oker1)

Referencing base box files in Vagrantfile

I was trying to create a vagrant box for a development environment, which can be easily distributed and used by other developers. I’ve created a base box using debian squeeze, and made a vagrant box based on it. I’ve added puppet provisioning to it, changed the ssh key, etc. I had a fair amount of configuration in the Vagrantfile, which shouldn’t be changed by the users. I found out that one can include the Vagrantfile, and other files in the base box, and the base box’s Vagrantfile values will take precedence over the box’s own Vagrantfile.

One problem I ran into, and couldn’t figure out from vagrant’s documentation, was referencing the files included in the base box. With some googling, I found an issue on GitHub with this exact same question.

The solution is to use File.expand_path in the base box’s Vagrantfile for files included in the base box. An example to use a custom ssh key in the base box:

config.ssh.private_key_path = File.expand_path("../vagrantkey", __FILE__)
blog comments powered by Disqus

Recent Posts

Clean Puppet code 04 October 2011. CentOS with Vagrant and VeeWee 30 September 2011. Referencing base box files in Vagrantfile 25 September 2011. Hello Octocat! 24 April 2011.
Fork me on GitHub