Skip to content

Instantly share code, notes, and snippets.

@UtahDave
Created June 28, 2013 15:07
Show Gist options
  • Save UtahDave/5885384 to your computer and use it in GitHub Desktop.
Save UtahDave/5885384 to your computer and use it in GitHub Desktop.
#!/bin/bash
# /usr/local/bin/clone-prep
# vanilla-sl6.khresear.ch
#
# Clone preparation script
#
# Do not run if this machine is still named Vailla
if [ "$(hostname)" == "vanilla-sl6.khresear.ch" ]
then
exit 0
fi
# Do not run script again
head -n -3 /etc/rc.local | tee /etc/rc.local
echo "exit 0" | tee -a /etc/rc.local
# Nuke networking stuff
head -n -5 /etc/sysconfig/network | tee /etc/sysconfig/network
service network restart
# Remove+regenerate SSH keys
rm -f /etc/ssh/sshd_host_dsa_key /etc/ssh/sshd_host_dsa_key.pub
rm -f /etc/ssh/sshd_host_rsa_key /etc/ssh/sshd_host_rsa_key.pub
service sshd restart
# Change Salt ID
sed -i "s/id: vanilla-sl6/id: $(hostname -s)/g" /etc/salt/minion
rm -rf /etc/salt/pki/minion/
service salt-minion restart
# Remove clone-prep script
rm -f /usr/local/sbin/clone-prep

These are installed into a "base image" which is configured as a Salt Minion. It is based upon Scientific Linux 6(a RHEL rebuild, akin to CentOS). A VMware Cloning Customization Specification is used to clone this machine. Options used in the specification are the new hostname+domain name, and NIC settings of "DHCP". Upon first boot, the VMware Tools set the machine's hostname + network settings and reboot the machine. The clone-prep script is triggered on the second boot, and performs the necessary work to generate a fresh minion identity and finish fiddling with the network. Once the new minion has been accepted into the master, state.highstate is used to load the permanent network settings, and cmd.run to reboot the machine a third time for everything to take effect.

A copy of the rc.local and /etc/sysconfig/network files, which are modified by this script, is included for reference. Depending upon the format of these files in your base image lines 15&19 may need modification.

#
# /etc/sysconfig/network
# vanilla-sl6.khresear.ch
#
# Note: this file is managed by salt. Any changes you make WILL be overwritten.
#
HOSTNAME="vanilla-sl6.khresear.ch"
NETWORKING="yes"
NETWORKING_IPV6="yes"
GATEWAY="10.90.0.1"
IPV6_DEFAULTGW="2001:470:58:1::1"
#!/bin/sh
# /etc/rc.local
# vanilla-sl6.khresear.ch
#
# Lockfile
touch /var/lock/subsys/local
# Prep
/usr/local/sbin/clone-prep
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment