#!/usr/bin/bash set -eu NAME="$1" mkdir -p tmp mkdir -p vm-state # https://mop.koeln/blog/creating-a-local-debian-vm-using-cloud-init-and-libvirt/ # > DO NOT DOWNLOAD THE GENERICCLOUD IMAGE IMG=debian-12-generic-amd64.qcow2 if ! [ -f "tmp/$IMG" ]; then curl -L -o "tmp/$IMG" https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2 fi DISK="vm-state/$NAME.qcow2" cp "tmp/$IMG" "$DISK" meta_data=$(mktemp) cat >"$meta_data" </dev/null; do echo "waiting for VM to start up and get an IP" sleep 1 done ip=$(virsh domifaddr "$NAME" | grep ipv4 | awk '{print $4}' | cut -d/ -f1) echo "IP: $ip" echo "$ip" >> vm-state/inventory.ini