Virtualization

Automate KVM Provisioning With Bash and virsh

Validate a declarative guest inventory before changes; Provision multiple predictable guests; Rerun with no duplicate resources or identity drift; Run scoped cleanup against only the episode prefix.

By InventiveHQ Team

Episode 17 of the InventiveHQ KVM virtualization series.

Lab verified July 2026 · Ubuntu 26.04 · libvirt 12.0.0 · QEMU 10.2.1

What this episode proves

  • Validate a declarative guest inventory before changes
  • Provision multiple predictable guests
  • Rerun with no duplicate resources or identity drift
  • Run scoped cleanup against only the episode prefix

Validated workflow

1. Validate a declarative guest inventory before changes

./deploy-fleet.sh inventory.tsv ~/.ssh/id_ed25519.pub

2. Provision multiple predictable guests

virsh list --all

3. Rerun with no duplicate resources or identity drift

./deploy-fleet.sh inventory.tsv ~/.ssh/id_ed25519.pub

4. Run scoped cleanup against only the episode prefix

./cleanup-fleet.sh inventory.tsv

Finished state

The idempotent provisioning and cleanup scripts remain; proof guests are removed. The public scripts contain no private keys, passwords, or tokens. Review names, addresses, paths, ownership, backups, quorum, and fencing for your own environment before running them.