Well, I’ve been fiddling around with SLES and openSUSE VMware templates. I know it’s a stupid idea when you have a PXE server from which you could install this in a matter of minutes (seriously the SLES PXE installation takes about 5 minutes).
However, when dealing with DMZ’s (yeah, they exist!) you usually don’t have any PXE servers there. So I decided to go with simple VMware templates (like we do with Windows already), but had to iron out a few kinks.
- There’s no way to run a set of scripts after the deployment scripts from VMware have been run
- The hostname isn’t changed everywhere (/etc/postfix/main.cf for example)
So of I went and wrote a short (70 line ..) init script, which will do exactly that.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
| #!/bin/sh
#
# /etc/init.d/template-deploy
#
### BEGIN INIT INFO
# Provides: template-deploy
# Required-Start: $sshd
# Should-Start:
# Required-Stop: $sshd
# Should-Stop:
# Default-Start: 2 3 5
# Default-Stop:
# Short-Description: Makes the final adjustments when deployed a template
# Description: VMware has a few kinks when deploying a linux template.
# This init script will handle those kinks and
# incorporate the necessary changes to the final system
# after the VMware customizations are done.
### END INIT INFO
# Source LSB init functions
. /etc/rc.status
rc_reset
LOGFILES="/var/log/messages* /var/log/mail* /var/log/zypper.log /var/log/localmessages /var/log/warn /var/log/NetworkManager /var/log/zypp/history /var/log/clamd.log /var/log/cksquid.log /var/log/ftp-proxy.log* /var/log/apache2/*_log /var/log/squid/*.log /var/log/pbl.log"
case "$1" in
start)
# Read /etc/HOSTNAME and check it against /etc/template
if [ -f /etc/HOSTNAME -a -f /etc/template ] ; then
SYS_HOSTNAME="`cat /etc/HOSTNAME`"
TPL_HOSTNAME="`cat /etc/template`"
# Only if the hostname isn't like the template name
# the script will actually run.
if [ "$SYS_HOSTNAME" != "$TPL_HOSTNAME" ] ; then
sed -i "s/$TPL_HOSTNAME/$SYS_HOSTNAME/g" \
/etc/postfix/main.cf /etc/hosts \
/etc/HOSTNAME
bash /var/adm/autoinstall/scripts/configure_users.sh
# Stop services for logfile deletion.
systemctl stop postfix
systemctl stop syslog
# Remove log files
for file in $LOGFILES; do
rm -f $file
done
rm -f /var/log/YaST2/*
rm -rf /var/log/vmware-imc
# Remove the init script
chkconfig -d template-deploy
rm -f /etc/template
rm -f /etc/init.d/template-deploy
fi
fi
rc_status -v
;;
*)
;;
esac
rc_exit
|
You’ll also need to create a file (/etc/template), which’ll hold the template’s hostname and will be used for the comparison if VMware’s post-processing is already finished.