summaryrefslogtreecommitdiff
path: root/README
blob: e1ce7a4d4bffc231b4ce997344b2ff4b71db2cf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Managing my virtual machines
============================

I have a laptop with 16 GiB RAM, which is enough to run a few virtual
machines. I make use of this to run VMs as, for example, workers for
my CI setup, such that I have two or three versions of Debian
(oldstable, stable, unstable) and two CPU architectures (i386, amd64).
This lets me test the software I develop on a large fraction of the
environments in which my users run it on.

I have a few other VMs as well. Managing all of these would be tricky,
but I've gathered some tools for this:

* The actual virtualisation is KVM, managed by libvirt. This is less
  invasive than running OpenStack of similar cloud services on my
  laptop.

* I use Ansible for configuration management. It's easy to use, and
  doesn't require Ruby or running an agent on each machine.

* I create each VM from a base image. The base images are created by
  vmdebootstrap, a tool I wrote and that Neil Williams now maintains.
  The base images have a minimal install, with a user `ansible` that
  is allowed passwordless sudo, and an `authorized_keys` file that
  allows my Ansible to log into them and do things.

The creation of a new VM is a somewhat intricate process:

* Create a new LV of the same size as the base images.

* Unpack the correct base image onto the LV. The base images are
  stored compressed in an archive location.

* Create the VM, with `virt-install`. This chooses a random MAC
  address for the new VM, and also starts it.

* Find the new VM's MAC address in the
  `/var/lib/libvirt/dnsmasq/default.leases` file, and pick out the IP
  address given to it.

* Add to `/etc/hosts` a line that gives the VM's IP address a name
  that's the new VM's hostname.

All of the above is automated into a script.

After this, the new VM can be managed by Ansible. Ansible gets run
manually after the VM creation script, and after I've added the new VM
to my Ansible config.