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?
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 {}
Vagrantfile could have the boxes in variables, thus statically grepping the Vagrantfile won't succeed in all scenarios.
Following is another approach that captures the names created by vagrant status
vagrant status | \
awk '
BEGIN{ tog=0; }
/^$/{ tog=!tog; }
/./ { if(tog){print $1} }
' | \
xargs -P2 -I {} vagrant up {}
vagrant status
gets a report of the machines that are managed by the Vagrantfile
, printed as a machine-per-line between 2 empty lines. awk
command captures all the machine-lines between the 2 empty lines and prints the first word of each machine-line (which are the machine names). xargs
command changes stream into arguments that could be utilized in parallel using the -P
option.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With