Last updated

Building armies of servers with kvm and puppet

Articles by George Ornbo, a London-based technologist

Estimated reading time: 2 minutes

Table of contents

Our infrastructure requirements at pebble {code} are growing. We’ve got pretty far with an original Ubuntu 8.04 -> 10.04 Linux server. It has been a workhorse for us but an incident with bad sectors and no RAID facility suggested it was time for a more grown up solution.

We purchased a beefy server from Dell and have chosen to use kvm to manage virtual machines on the server. You can install kvm during the Ubuntu 12.04 Server install process and there is also good documentation available on the Ubuntu site. We have configured a bridged setup to allow virtual machines to be accessed directly on an IP address.

We use ubuntu-vm-builder to create virtual machines and found that setting defaults in /etc/vmbuild.cfg is a good idea.

arch   = amd64
domain =
mask   =
net    =
bcast  =
gw     =
dns    =
user   = YOURUSER
name   = YOUR NAME
firstboot = /etc/vmbuilder/firstscripts/

libvirt = qemu:///system
bridge = br0
virtio_net = true
mem     = 1024
cpus    = 2

suite = precise
flavour = virtual
components = main,universe
addpkg = openssh-server, git, vim, puppet

With the defaults set it is possible to bring up a machine ready to roll with the following.

sudo ubuntu-vm-builder kvm --dest DESTINATION --hostname HOSTNAME --ip IP

Using the firstboot option in /etc/vmbuild.cfg you can run a script on first boot. We use this to connect the new server to our Puppet Master.

#!/bin/sh -e
#execute only once
if [ ! -e /root/firstboot_done ]; then
echo "[agent]" >> /etc/puppet/puppet.conf
echo "server =" >> /etc/puppet/puppet.conf
# Start puppet on boot?
echo "START=yes" >> /etc/default/puppet

# Restart Puppet
sudo service puppet restart

# Touch firstboot_done so we don't run this anymore!
touch /root/firstboot_done
exit 0

This script starts sets the location of the Puppet Master and then starts the Puppet Agent. After signing the certificate on the Puppet Master the manifests for the new server then build the server how we want it. End-to-end we can now provision new servers within about 5 minutes. Next up support for Windows guests..

Have an update or suggestion for this article? You can edit it here and send me a pull request.


Recent Posts