#!/usr/bin/env bash set -euo pipefail PROXMOX_HOST="${PROXMOX_HOST:-root@192.168.2.193}" VMID="${VMID:-105}" VM_NAME="${VM_NAME:-ansible-control}" VM_CORES="${VM_CORES:-2}" VM_MEMORY_MB="${VM_MEMORY_MB:-4096}" VM_DISK_GB="${VM_DISK_GB:-40}" VM_BRIDGE="${VM_BRIDGE:-vmbr0}" VM_STORAGE="${VM_STORAGE:-local-lvm}" ISO_STORAGE="${ISO_STORAGE:-local}" ISO_FILE="${ISO_FILE:-ubuntu-24.04.4-live-server-amd64.iso}" ssh -o StrictHostKeyChecking=no "${PROXMOX_HOST}" bash </dev/null 2>&1; then echo "VMID ${VMID} already exists; refusing to overwrite" exit 1 fi if [ ! -f "/var/lib/vz/template/iso/${ISO_FILE}" ]; then echo "ISO /var/lib/vz/template/iso/${ISO_FILE} not found" exit 1 fi qm create "${VMID}" \ --name "${VM_NAME}" \ --ostype l26 \ --machine q35 \ --bios ovmf \ --cpu x86-64-v2-AES \ --cores "${VM_CORES}" \ --memory "${VM_MEMORY_MB}" \ --scsihw virtio-scsi-single \ --net0 virtio,bridge="${VM_BRIDGE}",firewall=1 qm set "${VMID}" --efidisk0 "${VM_STORAGE}:4,efitype=4m,pre-enrolled-keys=1" qm set "${VMID}" --scsi0 "${VM_STORAGE}:${VM_DISK_GB},iothread=1" qm set "${VMID}" --ide2 "${ISO_STORAGE}:iso/${ISO_FILE},media=cdrom" qm set "${VMID}" --boot order=scsi0 qm set "${VMID}" --onboot 1 qm start "${VMID}" echo "Created and started VM ${VMID} (${VM_NAME})." echo "Complete Ubuntu install in console, then assign static IP 192.168.2.105 and user 'dan' SSH key auth." EOF