Creating a CentOS 7 VMware Gold Template – Updated for Deployment Fix
23rd February 2015I have created a new post here that details the most up to date information for CentOS 7.x Templates.
I have documented how to create a CentOS 7 VMware Gold Template for all the non-Linux admins out there.
Following the instructions below will yield a template ready for future installs that ensures you can deploy at speed.
All told this should take no longer than 15 minutes to complete.
I have amended the post with details on how to fix the guest customisation issues that I was experiencing before.
I can now successfully deploy new VM’s from the template.
Creating the VM
As a fan of the C# client I have used that for the process of creating the CentOS 7 Template, obviously if you want to do this via the web client you’re more than welcome to do so.
Use Ctrl + N to open the New Virtual Machine wizard.
Accept the Typical configuration and click Next
Enter the name of the template and click Next
Select your Resource Pool and click Next
Select your Datastore and click Next
Choose your OS type and version, click Next
Choose your Network and change your adapter type if required, the VMXNET3 driver is present during the installation process and is the default card, click Next
Choose your disk provisioning policy and click Next
Click the Edit VM settings box
Browse to your ISO file, click Connect at power on and then remove the floppy drive, click Finish
Installing CentOS 7
Now we have the VM created we need to install the OS, select the VM, open the console and hit the green arrow to power on
Click in to the VM and use the up cursor to skip the Media Test and select Install CentOS 7
Choose your default language and locale, click Continue
Select Software Selection
I chose Infrastructure Server as this looks to be the replacement for the older Basic Server install that a lot of people defaulted to. Click Done
Select Installation Destination
Click Done
Click Network & Hostname
Toggle the On\Off switch so that you’re connected. All being good when you chose your network (and you have DHCP active on your network) you should get an address, if you don’t click on the Configure button and enter the IP addressing details there. I have left the hostname as the default setting as this will be changed during deployment. Click Done
Click Begin Installation
Select Root Password
Enter your default password twice, click Done
Wait for the installation to finish
Click Reboot
Installing CentOS 7 Software Updates and Open-VM-Tools
Using either Putty or the console log in to the server
Here I am still using the VM Console to access the VM
Login as root
Now we are going to install updates using yum.
Type yum update –skip-broken
skip-broken is a feature in yum to skip packages that have dependency problems or introduce problems to the installed packages
Type y when prompted to download the updates.
Type y
Update complete, now on to installing open-vm-tools
Type y
Final Steps
As this VM is being built to create a template from we need to add an additional VMware tools plug-in.
First we need to import the VMware Keys.
Using the curl command to download the two files to a directory
curl –o filename.ext http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-DSA-KEY.pub
curl –o filename.ext http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-RSA-KEY.pub
You then need to import the keys, you need to repeat the command twice.
rpm --import /key_path/key_name
Once that’s done we need to use nano to create the following file
/etc/yum.repos.d/vmware-tools.repo
The file needs to contain the following information
[vmware-tools]
name = VMware Tools
baseurl = http://packages.vmware.com/packages/rhel7/x86_64/
enabled = 1
gpgcheck = 1
Type Ctrl x to save and exit.
Now we need to install the additional plug-in.
Type yum install open-vm-tools-deploypkg
Type y
Installation completed. Time to restart the service
systemctl restart vmtoolsd
After the service restart we can see that VMware Tools is now reporting in.
Finally before we power off to convert it to a template we need to make some final changes, this change forces vCenter to think that this is a RHEL 7 VM rather than CentOS 7 which allows the VM to run the guest customisation during deployment.
Currently if you run cat /etc/redhat-release you will get the following response
What we want to see is
This forces guest customisation to be run thinking the OS is RHEL7 and thereby allowing guest customisation during deployment.
To make the change run the following command
rm -f /etc/redhat-release && touch /etc/redhat-release && echo ‘Red Hat Enterprise Linux Server release 7.0 (Maipo)’ > /etc/redhat-release
The above command was found via the http://serverfault.com/questions/653052/from-vsphere-5-5-deploying-centos-7-from-template-ignores-customizations website so thanks guys.
We are now ready to power down the VM.
Type shutdown –P now this will shutdown and power off the VM.
Finally we are going to convert it to a template.
In the C# client browse to the VM Summary page and click on Convert to Template
Thank you. This worked great!
Check your screenshot of the repo config, I think it comes up before the step to actually do it,
Thanks Louis, I have corrected that.
Don’t forget to unattach the ISO before converting to template.
Hi,
could you please tell us on which version of Esxi and Vcenter did you realize the template ?
Because I am in Esxi 5.5 update 1 with Vcenter 5.5 update 1 and I don’t have CentOS 7 in the Guest operating system list from the vpshere client (not the web one) at the VM creation.
Regards
Hi Laurent,
This was created on vSphere 6 infrastructure as that was the first version to support CentOS 7.
Regards,
Simon
The step about downloading the keys from VMware is not clear where to download them – is that important?
Jon,
Using the curl command mentioned above will download those keys directly for you. Yes it’s needed.
Simon
So…you don’t delete the SSH keys from your template? (all your VMs will use the same keys, very bad!), you don’t empty logs, don’t delete unique identifiers from network interfaces, don’t delete history of commands…this is missing a lot IMHO.
It’s used in my homelab only, if I was going to be using this in the field then I would be relying on either chef or puppet runs. It would also be deployed using something like VCD or VRA. Whilst it’s missing a lot to you, for my home lab environment it’s working as required.
Of course, you don’t have to use the information here and are more than welcome to provide your own 🙂