Skip to content

Instantly share code, notes, and snippets.

@kkroesch
Last active March 11, 2024 10:04
Show Gist options
  • Save kkroesch/cfdb589f0c6ce3d17f232a268649a5bc to your computer and use it in GitHub Desktop.
Save kkroesch/cfdb589f0c6ce3d17f232a268649a5bc to your computer and use it in GitHub Desktop.
Manage VirtualBox VMs with Ansible
running_vms=($(VBoxManage list runningvms | awk '{print $1}' | tr -d '"'))
# Create Ansible inventory file
GROUP_NAME="local_vms"
for vm in $running_vms
do
vboxmanage guestproperty get "$vm" "/VirtualBox/GuestInfo/Net/0/V4/IP"
done |
awk -v group="$GROUP_NAME" '
BEGIN { printf("[%s]\n", group)}
{ print $2 }
' > hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment