Specify Vagrantfile path explicity, if not plugin Specify Vagrantfile path explicity, if not plugin ruby ruby

Specify Vagrantfile path explicity, if not plugin


Further to Andrew Lorente's answer, you can also use the VAGRANT_VAGRANTFILE environment variable to specify the filename of the Vagrantfile. This has the advantage over VAGRANT_CWD of not changing the current working directory which can be useful when relying on relative paths.

For example, the following will run vagrant up on Vagrantfile.other:

VAGRANT_VAGRANTFILE=Vagrantfile.other vagrant up

Notes


There is no need to have a separate Vagrantfile, you can just define multiple VM's in the same file. See the documentation here: http://docs.vagrantup.com/v2/multi-machine/index.html

If you are just using one VM in your 'normal' environment and one VM for your 'confluence' environment then it is simply a case of just defining each VM and vagrant up-ing the specific VM.

If you have multiple machines that make up each of your environments then you have two options, you can use regular expressions and make sure you name and type the commands correctly or you can put a bit of logic into your Vagrantfile to make it easier for people.

For example with a little bit of a hack in your Vagrantfile you can do the following:

Vagrant.configure('2') do |config|    if ARGV[1] == 'confluence'        ARGV.delete_at(1)        confluence = true    else        confluence = false    end    config.vm.provider :virtualbox do |virtualbox, override|        #virtualbox.gui = true        virtualbox.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]        virtualbox.customize ["modifyvm", :id, "--memory", 512]        override.vm.box = 'Ubuntu 12.10 x64 Server'        override.vm.box_url = 'http://goo.gl/wxdwM'    end    if confluence == false        config.vm.define :normal1 do |normal1|            normal1.vm.hostname = 'normal1'            normal1.vm.network :private_network, ip: "192.168.1.1"        end        config.vm.define :normal2 do |normal2|            normal2.vm.hostname = 'normal2'            normal2.vm.network :private_network, ip: "192.168.1.2"        end    end    if confluence == true        config.vm.define :confluence1 do |confluence1|            confluence1.vm.hostname = 'confluence1'            confluence1.vm.network :private_network, ip: "192.168.1.3"        end        config.vm.define :confluence2 do |confluence2|            confluence2.vm.hostname = 'confluence2'            confluence2.vm.network :private_network, ip: "192.168.1.4"        end    endend

Now vagrant up brings up your normal vm's and vagrant up confluence brings up your confluence vm's!


While other answerers are correct that this particular case didn't need separate Vagrantfiles, I think there are legitimate uses for specifying a Vagrantfile path--reading vagrant ssh-config information in a script, for example.

Happily, you can do it by setting the VAGRANT_CWD environment variable:

VAGRANT_CWD=~/some/path/ vagrant ssh-config

This doesn't appear to be documented anywhere, but you can see it in the source.