VMware Template – Ubuntu 18.04.3 LTS

Posted on Posted in Ubuntu, VMware

Thanks to VMUG advantage I’m running the latest and greatest versions of ESXi and vCenter Server. However, applying a simple VM customization during Ubuntu 18.04.3 template deployment resulted in the network being set but not connected even though the template was.

I ended up combining parts of this helpful script seen at Jim Angel’s site along with VMware’s original resolution to get things sorted in my environment.

Throw the following into a file on your system, make it executable, and sudo bash to prep for converting to template.


echo Update system
apt update -y && apt upgrade -y

echo Stop rsyslog
service rsyslog stop

echo Empty log files
find /var/log/ -type f -exec cp /dev/null {} \;

echo Remove tmp files
rm -rf /tmp/*
rm -rf /var/tmp/*

echo Remove host SSH keys
rm -f /etc/ssh/ssh_host_*

echo Create /etc/rc.local to regenerate ssh host keys if needed
cat << 'EOL' > /etc/rc.local 
if [ ! -e /etc/ssh/ssh_host_rsa_key ]; then
  dpkg-reconfigure openssh-server
  systemctl restart ssh
exit 0
chmod +x /etc/rc.local

echo Clean apt
apt clean

echo Clean cloud-init logs
cloud-init clean --logs

echo Clear machine-id
cp /dev/null /etc/machine-id

echo Remove unwanted MOTD detail
chmod -x /etc/update-motd.d/10-help-text
chmod -x /etc/update-motd.d/50-motd-news

#vmware customization fix https://kb.vmware.com/s/article/56409

if grep -E '^#D \/tmp 1777 root root' /usr/lib/tmpfiles.d/tmp.conf
  echo VM tools tmp.conf customizations already exists 
  echo Adding VM tools tmp.conf customization
  sed -i 's/^D \/tmp 1777 root root -/#D \/tmp 1777 root root -/' /usr/lib/tmpfiles.d/tmp.conf

if grep -E '^After=dbus.service' /lib/systemd/system/open-vm-tools.service
  echo VM tools service customization already exists 
  echo Adding VM tools service customization
  sed -i '/^\[Unit\]/a\After=dbus.service' /lib/systemd/system/open-vm-tools.service

echo Clear bash history
cp /dev/null ~/.bash_history && history -cw

echo shutdown
# uncomment if you want to shutdown immediately
#shutdown now

# you may want to run history -cw as your logged in account too