Puppet, VirtualBox and Interfaces

At work we’re using a small Python script to

  • do some sanity checking (hostname checks, acquiring IP address etc)
  • clone a VirtualBox machine (needs to be stopped because of Bug 9255)
  • modify machine to according # of CPUs and amount of RAM
  • mount the disk locally,
  • mount the disk’s first partition locally,
  • put SSH keys in place, used during initial provisioning,
  • update network setting files, including udev rules (/etc/udev/rules.d/70-persistent-net.rules) to get predictable network card names and being able to map them to IP addresses
  • unmount all above,
  • generate new DNS and basic Puppet manifest files, reload services (puppet),
  • boot it,
  • run puppet agent on the new machine to generate and push client signing request to puppetmaster
  • sign cert on puppetmaster,
  • run puppet to have the machine finish it’s provisioning (overwrites the SSH keys)

Done. :-)

To issue commands over SSH we’re using Fabric (and might, or might not, move to using Serf).

Upstart and Virtualbox

Upstart script for starting and stopping Virtualbox machines. This goes into /etc/init/vbox-agila-ledare.conf (which could be paremetrized, look this up in the upstart cookbook).

#
# Upstart receipt for starting Virtualbox machines after reboot
#
description "VM for agila-ledare.se"
author "Fredrik Wendt"

start on start-vbox-machines
stop on runlevel [016]

console output

pre-stop script
  su vbox -c "VBoxManage controlvm agila-ledare savestate"
end script

script
  exec su vbox -c "VBoxHeadless --startvm agila-ledare"
end script