September 10, 2020 | 11:00

Script for Testing-Farm

Yesterday evening somebody desperately fought in despair with Packer, the younger sister of Vagrant. The goal was to create a testing farm of n machines for Virtualbox and make them accessible via SSH for further automated software testing/rollout.

For me, this is much easier by using a simple bashscript. This morning I’ve made one even before the very first cup of coffee.


# Pfad zur Master .ova Datei

# Anzahl der gewünschten VMs

# Name der VMs (Index und Datum werden noch angefügt = NAME-n-YYYYMMDD)

# Anzahl der CPUs

# Zugewiesener Speicher

# Datums-Suffix
THE_DATE=$(date +%Y%m%d)

# Logdatei zum prüfen

# -- Bitte ab hier nichts mehr manuell anpassen --

echo "Beginne Erstellen der Testumgebung... (Start: $(date +%T))" > $THE_LOG

for ((i=1; i<= $AMOUNT; i++)) 
  vboxmanage controlvm $PREF_VMNAME-$i-$THE_DATE poweroff >> $THE_LOG
  vboxmanage unregistervm $PREF_VMNAME-$i-$THE_DATE --delete >> $THE_LOG
  vboxmanage import $MASTER_OVA --vsys 0 --cpus $PREF_CPU --memory $PREF_MEMORY --vmname $PREF_VMNAME-$i-$THE_DATE >> $THE_LOG
  vboxmanage startvm $PREF_VMNAME-$i-$THE_DATE  --type headless >> $THE_LOG

echo "...fertig! (Ende: $(date +%T))" >> $THE_LOG 

The script creates n boxes based on its .ova MASTER. I assume that all network settings (if bridged, NAT or anything else) are specified there. Alongside with a transferred SSL-ID for Ansible, if necessary. The whole setup can of course be done without a master by using createvm inside the for-loop, your milage may vary.

Have fun!

© 2020 Tomas Jakobs - Imprint and Legal Notice