Saving time with VM templates

Image that you need to provision 1000 virtual machines for new web server farm. Doing this manually can be boring and can take long time answering all installation questions, patching and updating base OS to get it in right shape.

There is a better way by utilizing VM templates. Templates are like golden images, you install the OS once, do all changes you need to and than you convert it into a template that can be later used to create identical clones.

There is however one problem with clones, and that is that they are same in almost every way. We need to modify these clones to include some uniqueness such as hostnames, ip addresses, public/private keys. Some operating system such as Windows support sysprep which are set of scripts that can modify the Operating System as it being deployed, which makes it easy to perform changes during deployment.

The support for most linux operating systems customization wizard was discontinued in vSphere 5. So you need to look at another way like Puppet or Chef.

Converting a virtual machine into a template is easy, just right click on it and select Clone to Template.  In this example I am using the previously updated Debian 7.8 guest that has open VM tools installed.


The vCenter will mark the virtual machine as a template and will remove it from the main Hosts and Clusters window to VMs and Templates. Browser to that location and highlight the newly created template.

You will now have an option to either Deploy Virtual Machine form this Template or Convert back to Virtual Machine.


We are going to select the first option, and after answering questions like how to name the new VM, and where to place it, validation check occurs and the new guest will be deployed.

This is also the one of the places to make changes virtual disk, such as migrating from Thick to Thin provisioning.

After switching to new VM Console, you will be be presented by deb01 login prompt. You can use the following script to rename the box to deb02. Execute and then do a quick reboot.

usage() {
   echo "usage : $0 <new hostname>"
   exit 1

[ "$1" ] || usage


for file in \
   /etc/exim4/update-exim4.conf.conf \
   /etc/printcap \
   /etc/hostname \
   /etc/hosts \
   /etc/ssh/ \
   /etc/ssh/ \
   /etc/motd \
   [ -f $file ] && sed -i.old -e "s:$old:$new:g" $file
Depending on our network configuration, you may also need to change IP addresses if you are not using DHCP to avoid collisions. And also shuffling SSH keys would be a good idea too.
Anyway, this is a great way for home lab when you want to create lots of test machines and test features like load balancing. You can create various flavors from the vanilla template like web server or database server.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s