gy2eng
Last Updated: February 25, 2016
·
1.306K
· jabclab
4f4bf0fbd4cc6de6159d78f9f9fb3aa6

Bring Vagrant VMs up in parallel

We were facing an issue when using the vagrant-rackspace plugin where the creation of VMs was done in series.

As the plugin is effectively a wrapper around OpenStack there is no reason why this can't be done in parallel. We managed to get the VMs created in parallel as follows:

#!/usr/bin/env bash
IFS=$'\n' vm_names=(`vagrant status --machine-readable | awk '{FS=","} { print $2 }' | uniq`)

for vm in "${vm_names[@]}"; do
  echo "[$vm] Bringing up VM"

  vagrant up $vm --no-provision &
done

# Make sure all child processes have finished before exiting.
wait

echo "Cloud VMs are up"

This dynamically looks up the names of the VMs defined by Vagrant but of course you could hardcode using something like:

vm_names=( 'app_server' 'db_server' )
Say Thanks
Respond
Filed Under