Please notice: This article is more than 3 years old
Content, Source code or links may no longer be correct in the meantime.
Please notice: This article is more than 3 years old
Content, Source code or links may no longer be correct in the meantime.
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.
#!/bin/bash
# Pfad zur Master .ova Datei
MASTER_OVA="$HOME/projects/testingfarm/DebianBuster.ova"
# Anzahl der gewünschten VMs
AMOUNT=2
# Name der VMs (Index und Datum werden noch angefügt = NAME-n-YYYYMMDD)
PREF_VMNAME="debian"
# Anzahl der CPUs
PREF_CPU=1
# Zugewiesener Speicher
PREF_MEMORY=1024
# Datums-Suffix
THE_DATE=$(date +%Y%m%d)
# Logdatei zum prüfen
THE_LOG="$HOME/projects/testingfarm/$THE_DATE-$PREF_VMNAME.log"
# -- Bitte ab hier nichts mehr manuell anpassen --
echo "Beginne Erstellen der Testumgebung... (Start: $(date +%T))" > $THE_LOG
for ((i=1; i<= $AMOUNT; i++))
do
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
done
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 SSH-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!