Pages

Friday, February 7, 2014

Red Hat Kickstart - Prompting for input

I have progressed in my implementation of Red Hat Satellite to the point of setting up a kickstart file for automated deployments.  Setting up the kickstart file throught he Satellite web interface was pretty easy to do. I was deploying a fully automated RHEL installation fairly quickly.

I wanted more though. I want all the normal stuff that I normally have to do after installation to already be done.  Such as setting the hostname and IP Address.  From my research, the way to do this is with pre and post scripts in the kickstart file.

To start off simple, I wanted the kickstart process to prompt me for hostname, IP and gateway.  Here is what I came up with for my pre and post sections:

%pre
#change to tty6 to get input
chvt 6
exec </dev/tty6 > /dev/tty6

#Get hostname
echo "What is my hostname?"
read NAME

#Get IP
echo "What is my IP?"
read ADDR 

#Get Gateway
echo "What is the Gateway?"
read GW


#build /etc/sysconfig/network
echo "NETWORKING=yes" > network
echo "HOSTNAME=${NAME}" >> network
echo "GATEWAY=${GW}" >> network

#build /etc/sysconfig/network-scripts/ifcfg-eth0
echo "DEVICE=eth0" > ifcfg-eth0
echo "BOOTPROTO=none" >> ifcfg-eth0
echo "IPV6INIT=no" >> ifcfg-eth0
echo "MTU=1500" >> ifcfg-eth0
echo "NM_CONTROLLED=no" >> ifcfg-eth0
echo "ONBOOT=yes" >> ifcfg-eth0
echo "TYPE=Ethernet" >> ifcfg-eth0
echo "IPADDR=${ADDR}" >> ifcfg-eth0
echo "NETMASK=255.255.254.0" >> ifcfg-eth0

#change back to tty1 and continue script
chvt 1
exec < /dev/tty1 > /dev/tty1
%end

%post --nochroot
# bring in hostname collected from %pre
cp network /mnt/sysimage/etc/sysconfig/network
. /mnt/sysimage/etc/sysconfig/network
# force hostname change
/mnt/sysimage/bin/hostname $HOSTNAME

#copy prebuilt ifcfg-eth0 script to set IP
cp ifcfg-eth0 /mnt/sysimage/etc/sysconfig/network-scripts/ifcfg-eth0

%end

After I made these changes to my pre and post scripts, the kickstart processed asked me for the IP, Gateway and hostname.  When the install completed, all 3 were set correctly.

1 comment:

Admin said...

Can you add an article on how to setup kickstart on RHN 5.6 as well if time permits. Thanks for sharing all your knowledge.