Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually specify location of .vagrant folder in Vagrantfile

Tags:

vagrant

build

The folder where I have Vagrantfile is being auto-generated during the build, so it gets cleaned up, but I'd like to still be able to use the created machines. The easiest way would be to put .vagrant folder somewhere outside the auto-generated folder. Is this possible?

like image 755
Sergey Evstifeev Avatar asked Feb 13 '14 18:02

Sergey Evstifeev


People also ask

Where is the vagrant file located?

Vagrantfile in your Vagrant home directory (defaults to ~/. vagrant. d ). This lets you specify some defaults for your system user.

Which directory in your vagrant VM is the synchronized folder?

Vagrant automatically syncs files to and from the guest machine. This way you can edit files locally and run them in your virtual development environment. By default, Vagrant shares your project directory (the one containing the Vagrantfile) to the /vagrant directory in your guest machine.

Where is Vagrantfile located on Windows?

Windows: C:/Users/USERNAME/. vagrant.


2 Answers

You have (at least) two options:

  1. Use VAGRANT_DOTFILE_PATH to set the the location where the project specific data is stored (defaults to .vagrant as you already know). Note that the path has to be project/Vagrantfile specific.

  2. cd to a directory where you want the .vagrant directory to be created, and use VAGRANT_VAGRANTFILE to specify the path to the generated Vagrantfile.

like image 111
tmatilai Avatar answered Oct 22 '22 15:10

tmatilai


I know this is an old question, but for anyone arriving here via Google, there is a workaround if you really want to specify the metadata directory without mucking about with environment variables each time. Just put this in the top of your Vagrantfile:


VAGRANT_DOTFILE_PATH = 'custom/dotfile/path'
if(ENV['VAGRANT_DOTFILE_PATH'].nil? && '.vagrant' != VAGRANT_DOTFILE_PATH)
    puts 'changing metadata directory to ' + VAGRANT_DOTFILE_PATH
    ENV['VAGRANT_DOTFILE_PATH'] = VAGRANT_DOTFILE_PATH
    puts 'removing default metadata directory ' + FileUtils.rm_r('.vagrant').join("\n")
    system 'vagrant ' + ARGV.join(' ')
    ENV['VAGRANT_DOTFILE_PATH'] = nil #for good measure
    abort 'Finished'
end
like image 28
hair raisin Avatar answered Oct 22 '22 13:10

hair raisin