Provisioning VMs with cloud init

One of the easiest ways to deploy a virtual machine in oVirt is first to install the OS then turn it into a template. This will allow you to copy that template to deploy new instances. One mundane task after a new template is copied to a new instance is logging in, changing the IP, setting the hostname, setting up Puppet, running puppet, etc. cloud-init is the tool designed to fix that mundane task process by allowing those steps to be automated. oVirt/RHEV (as well as OpenStack, AWS, and others) allow you to pass in user data which is then supplied to cloud-init after the template is copied over and turned on. This allows for scripting on the new VM – easing deployment.

For my environment, I wanted a CentOS 7 template. To have that, I must first install CentOS on a new VM and seal it (Windows calls this Sysprep). Before I seal it, I must install cloud-init and any other tools I might use for deployment – such as puppet. Here are the steps to obtain just that:

* Install CentOS 7.2 Minimal on any new VM. Ensure to have LVM partitioning as you may want to extend the disk later. I have found that 10 GB is a good starting size.

* Install your base files – things you cannot live without (i.e. vim,puppet, etc).

* Seal the VM per RedHat instructions. I suggest following the instructions for sysunconfig:

  1. Log in to the virtual machine.
  2. Remove ssh host keys:
    # rm -rf /etc/ssh/ssh_host_*
  3. Set HOSTNAME=localhost.localdomain in /etc/sysconfig/network for Red Hat Enterprise Linux 6/CentOS 6 or /etc/hostname for Red Hat Enterprise Linux 7/CentOS 7.
  4. Remove the HWADDR line and UUID line from /etc/sysconfig/network-scripts/ifcfg-eth*.
  5. Optionally, delete all the logs from /var/log and build logs from /root.
  6. Run sys-unconfig

sys-unconfig will turn off the VM when it is completed. When it is turned off, right click the VM and select copy to template.