Vagrant Multi-Machine Parallel Start

2019-03-25 23:58发布

问题:

I'm trying to provision a master-master MySQL pair and they can only be configured correctly if both of them are up.

Vagrant.configure("2") do |config|
  web.vm.box = "centos/7"

  config.vm.define "primary" do |primary|
    .......
  end

  config.vm.define "secondary" do |secondary|
    .......
  end
end

I've run thru this multiple times and Vagrant only starts the second vm after the first one is up.

Is there any way to force Vagrant to start up two VM's at the same time?

回答1:

vagrant up supports parallel VM start with the key --parallel:

--[no-]parallel Enable or disable parallelism if provider supports it

Default vagrant provider VirtualBox doesn't support it, but you can start your VMs simultaneously using xargs, which supports parallel command execution with the key -P <max-procs> (example provided exactly for your Vagrantfile):

grep config.vm.define Vagrantfile | awk -F'"' '{print $2}' | xargs -P2 -I {} vagrant up {}


标签: vagrant