This post will show you how to deploy a VM fully operational in a few seconds in a vSphere environment. You must have a working template to use this script.
You will have to install VMware Tools on this template, or OVT (OpenVMwareTools). They are now fully supported by VMware. I would recommand to use them, just for an ease of use during your weekly vulnerability review 😉 Ideed during your OS upgrade, the OVT package will also be updated. More details on VMware knowledge base. (kb.vmware.com/kb/2073803)
You need to install vSphere SDK for perl on your work station to be able to follow this post.
During the deployment you will not only clone the VM with all the template configuration, you will also configure IPs, gateway, hostname, DNS, Timezone and you will choose on which cluster, datastore and folder you will deploy your VM. We are going to use the VMware “Configuration Wizard” to deploy your VM.
You understood well, one of the biggest part of the job is not to write the script, you have to configure a working template. You need to have VMware Tools installed (OVT) or VMware Tools themselves. After the cloning operation, the VM will be powered on and the customization process will apply.
I’m not going to show you how to build a template, there are many of ways to do it, from scratch with an ISO, by deploying an existing template and change some settings to fit your needs, by downloading an external appliance, etc. The only thing you need to do is to install OVT.
Now, on your work station, where you installed the vSphere PERL SDK, you can edit a new script, and paste the scripts requirement to connect to your vCenter :
Now we focus on this post objective : deploy a Linux VM with everything configured.
First, we need to declare our environment :
This is exactly what you might see in your inventory.
You need now to get all views :
Right now, if you passed all the checks, you know that you did not miss any deployment requirements.
Now we need to build some VMware Perl Objects to get the guest OS configuration working. You don’t have to custom this part.
Then, here are the VMware Objects for the VM itself, you may not change anything there neither :
Finally, 3 lines to deploy our VM :
Here is the full script :