I've come across a post by Marek Goldmann detailing the basics of running Fedora cloud images on kvm. I found it was a massive help, but only got me part-way toward what I wanted.

The documentation for cloud-init is sub-par from what I can find, so I thought I'd post this with my own modifications.

My requirements were:

  • Easy scriptable deployment (Marek's script got me 100% of this goal)
  • Static (sequential) IP assignments instead of DHCP
  • hostname != KVM domain name, making system replacements easier

Additionally, I changed some logic

  • Changed user-data to an external file, rather than a big echo line
  • Generic filenames (my-vm/root.qcow2 instead of my-vm/my-vm.qcow2)
  • Don't destroy & remove VMs with a conflicting name
  • Leave the bootstrapping files behind, in case I need to re-create the machine later (or I alter the template and want to revisit)
  • Changed some logging

Files (and hierarchy ) look like this:

When these are booted with my user-data, there is no password (R means random, but doesn't seem to work), which effectively means you can't log in to it with a password. There is an authorized key for the default user (cirwin), which means I can still ssh to these machines.

The virt-install-fedora.sh script incriments next-ip, and then uses sed to replace XXIP with the incrimented ip. So technically, this will only work up to 255 times before it breaks (probably 253 for a /24 subnet, and you may have conflicts).

Some unresolved issues:

  • Network config is obviously suboptimal. There is a network module for cloud-init, but I couldn't get it to work (it may not have been ported to Fedora)
  • I think systemd kills cloud-init if it runs for more than a minute or so, making yum install ... risky, and yum upgrade is right out

Ultimately, I've started using these for my in-house experimental machines. A new one can be ready to in about two minutes.