From vSphere 5.5 - Deploying Centos 7 from template ignores customizations
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
Solution 1:
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
Solution 2:
Solution: I changed /etc/redhat-release to a vSphere recognized value of "Red Hat Enterprise Linux Server release 7.0 (Maipo)", and I can now deploy a VM from my CentOS7 template with customizations applied just fine. Be sure to rm the existing /etc/redhat-release symlink first. See mjevange's answer for the elegant one liner solution.
Background: After creating and deploying a new Oracle Linux 7 (OEL7) template using the same method as above for CentOS 7 and having it WORK, I quickly realized what the issue was. Check it out:
Default /etc/redhat-release file in Centos7:
cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
Default /etc/redhat-release file in RHEL7/OEL7:
cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)
(Please note that the version files for CentOS and Oracle Linux are centos-release and oracle-release respectively. Do NOT touch those as they are the distro specific version files.)