9

Creating a CentOS 7 VMware Gold Template – Updated for Deployment Fix

I 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. centos7

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.

image

Accept the Typical configuration and click Next

image

Enter the name of the template and click Next

image

Select your Resource Pool and click Next

image

Select your Datastore and click Next

image

Choose your OS type and version, click Next

image

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

image

Choose your disk provisioning policy and click Next

image

Click the Edit VM settings box

image

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

image

Click in to the VM and use the up cursor to skip the Media Test and select Install CentOS 7

image

Choose your default language and locale, click Continue

image

Select Software Selection

image

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

image

Select Installation Destination

image

Click Done

image

Click Network & Hostname

image

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

image

Click Begin Installation

image

Select Root Password

image

Enter your default password twice, click Done

image

Wait for the installation to finish

image

Click Reboot

Installing CentOS 7 Software Updates and Open-VM-Tools

Using either Putty or the console log in to the server

image

Here I am still using the VM Console to access the VM

image

Login as root

image

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

image

Type y when prompted to download the updates.

image

Type y

image

Update complete, now on to installing open-vm-tools

image

image

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.

image

image

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

image

/etc/yum.repos.d/vmware-tools.repo

image

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.

image

Type yum install open-vm-tools-deploypkg

image

Type y

image

Installation completed. Time to restart the service

systemctl restart vmtoolsd

image

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

image

What we want to see is

image

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.

image

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

image

Simon

9 Comments

  1. Thank you. This worked great!
    Check your screenshot of the repo config, I think it comes up before the step to actually do it,

  2. 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

    • Jon,

      Using the curl command mentioned above will download those keys directly for you. Yes it’s needed.

      Simon

  3. 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 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *