我正在尝试将我的“dev”VM设置为主要,因此大多数命令(例如vagrant up
,vagrant halt
等)在“dev”VM上运行并忽略“阶段”VM,除非“ stage“VM名称在命令行中明确列出。这是我的Vagrantfile,但是当我运行vagrant up
时,两个虚拟机都被启动而不仅仅是“开发”。
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
def box_setup(config, ip, playbook, inventory)
config.vm.network :private_network, ip: ip
config.vm.provision "ansible" do |ansible|
ansible.playbook = playbook
ansible.inventory_path = inventory
# ansible.verbose = "vvv"
end
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# common settings shared by all vagrant boxes for this project
config.vm.box = "debian-7-amd64"
config.vm.box_url = "https://dl.dropboxusercontent.com/s/xymcvez85i29lym/vagrant-debian-wheezy64.box"
config.ssh.forward_agent = true
# development box intended for ongoing development
config.vm.define "dev", primary: true do |dev|
box_setup dev, \
"10.9.8.30", "deploy/playbook_dev.yml", "deploy/hosts/vagrant_dev.yml"
end
# stage box intended for configuration closely matching production
config.vm.define "stage" do |stage|
box_setup stage, \
"10.9.8.31", "deploy/playbook_full_stack.yml", "deploy/hosts/vagrant_stage.yml"
end
end
答案 0 :(得分:2)
主要标志似乎只适用于vagrant ssh
。
过去我使用以下方法来解决这个问题。
# stage box intended for configuration closely matching production
if ARGV[1] == 'stage'
config.vm.define "stage" do |stage|
box_setup stage, \
"10.9.8.31", "deploy/playbook_full_stack.yml", "deploy/hosts/vagrant_stage.yml"
end
end