From vSphere 5.5 – Deploying Centos 7 from template ignores customizations

centos7deploymentvmware-vsphere

I've been having troubles when deploying CentOS7 from template in that the customizations do not take effect. For the VM OS setting – I have selected RHEL7 as the OS rather than CentOS (previously having learned that lesson with Oracle Linux 6.5 at my previous job). It should work right? Not exactly.

Symptom:
After deploying a new VM from the CentOS7 template, on first boot the server comes up with the correct hostname, then the customization scripts execute, and after the VM reboots it has the original template hostname again, and while /etc/sysconfig/network-scripts/ifcfg-ether has the correct settings, the ifcfg settings for the correct nic (ifcfg-e*) have not been implemented.

Background:

I followed the VMWare's instructions for CentOS setup:
http://partnerweb.vmware.com/GOSIG/CentOS_7.html

After a few package additions (including net-tools which is required for vSphere customizations), I then buttoned up the template as follows using my "templatize script" (credit to http://lonesysadmin.net/2013/03/26/preparing-linux-template-vms/ for steps):

#!/bin/bash    
# clean yum cache
/usr/bin/yum clean all
#remove udev hardware rules
/bin/rm -f /etc/udev/rules.d/70*
#remove nic mac addr and uuid from ifcfg scripts
/bin/sed -i '/^\(HWADDR\|UUID\)=/d' /etc/sysconfig/network-scripts/ifcfg-eth0
#remove host keys (important step security wise.  similar to system GUID in Windows)
/bin/rm /etc/ssh/ssh_host_*
#engage logrotate to shrink logspace used
/usr/sbin/logrotate -f /etc/logrotate.conf
#and lets shutdown
init 0

Supported Versions where workarounds are no longer needed:

  • vSphere 5.5u3 (build 3000241 or higher)
  • vSphere 6.0 and higher

VMWare's "Guest OS Customization Support Matrix":
http://partnerweb.vmware.com/programs/guestOS/guest-os-customization-matrix.pdf

Best Answer

UPDATE: Just tested, this still works in Centos 7.1 using RHEL 6 as the guest OS option and the command below.

FYI redhat-release is symlinked to centos-release. If you edit redhat-release, you are actually modifying centos-release.

To follow the solution's recommendation in not modifying distro specific version files, do this instead:

rm -f /etc/redhat-release && touch /etc/redhat-release && echo "Red Hat Enterprise Linux Server release 7.0 (Maipo)" > /etc/redhat-release