Last Updated: February 25, 2016
· jabclab

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 &

# Make sure all child processes have finished before exiting.

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' )