有没有什么办法来明确地指定一个Vagrantfile的路径?我公司愿意做这样的事情:对于汇合机器上测试,键入像vagrant spinup confluence
一个命令,然后点说的Vagrantfile中包含汇合环境,然后系统会显示所有这些机器的不同目录。
但是,它看起来并不像有什么办法明确规定什么Vagrantfile使用,我在红宝石是有点(非常)新的,所以我有一个很难写我自己的插件吧。是否有人在做什么建议?或者有没有人做过类似这样的东西吗?
有没有需要有一个单独的Vagrantfile,你可以在同一文件中定义多个虚拟机。看到这里的文档:http://docs.vagrantup.com/v2/multi-machine/index.html
如果你只是用你的“正常”的环境中的一个虚拟机和一台虚拟机为您的“合流”的环境那么它是一个简单的定义只是每个VM和vagrant up
-ING的特定虚拟机的情况下。
如果你有多个机组成,每个环境,那么你有两个选择,你可以使用正则表达式,并确保你的名字,并输入正确的命令,也可以放一点逻辑到您的Vagrantfile,使人们更容易。
例如有一个黑客在你Vagrantfile你可以做以下的一点点:
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
end
end
现在qazxsw POI带来了正常的虚拟机和qazxsw POI带来了你的汇合VM的!
继安德鲁洛伦特的回答,您还可以使用vagrant up
环境变量指定vagrant up confluence
的文件名。这具有这样的优势不改变在相对路径依赖时可以是有用的当前工作目录的VAGRANT_VAGRANTFILE
。
例如,下面将上Vagrantfile
运行VAGRANT_CWD
:
vagrant up
Vagrantfile.other
。VAGRANT_VAGRANTFILE=Vagrantfile.other vagrant up
。而其他应答者是正确的,这种特殊情况下并不需要单独Vagrantfiles,我觉得有用于指定Vagrantfile路径合法用途 - 在脚本读取visible in the source code信息,例如。
令人高兴的是,你可以通过设置Environmental Variables环境变量做到这一点:
vagrant ssh-config
这似乎并没有在任何地方记录,但你可以看到它VAGRANT_CWD
。
只要你想/需要你可以有很多不同的VAGRANT_CWD=~/some/path/ vagrant ssh-config
s。只需为项目创建一个新的目录(然后可以仅仅由一个或多个虚拟机),然后in the source到该目录并运行Vagrantfile
使流浪创建一个新的cd
然后可以自定义您的需求。要使用新的vagrant init
刚刚从包含该文件的目录中运行Vagrantfile
开始你的虚拟机。
括号把shell命令创建一个子shell,所以从混帐的Windows(或在Linux / OS X的bash),你可以这样做:
Vagrantfile