9. Kickstart Templates with Cobbler

Cobbler uses a flexible Python-based template system called Cheetah to generate the final kickstart provided to a system during PXE boot. Each system or profile can have their own kickstart template assigned to it. This way you can either have a specific kickstart for a single server or the same kickstart for a group of systems.

Kickstart Generation

Kickstart Generation

Our systems so far all inherit their Kickstart template from their profile. You can see this if you look at the cobbler system report.

[root@master ~]# cobbler system report --name=c01 | grep Kickstart
Kickstart                      : <<inherit>>
Kickstart Metadata             : {}

[root@master ~]# cobbler system report --name=c01 | grep Profile
Profile                        : centos7-x86_64

The centos7-x86_64 profile created during cobbler import points to a sample kickstart file provided by cobbler.

[root@master ~]# cobbler profile report --name=centos7-x86_64 | grep Kickstart
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks
Kickstart Metadata             : {}

cobbler system getks allows you to see the final Kickstart of a system:

[root@master ~]# cobbler system getks --name=c01
# This kickstart file should only be used with EL > 5 and/or Fedora > 7.
# For older versions please use the sample.ks kickstart file.

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --enabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=http://192.168.16.1/cblr/links/centos7-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.16.1/cobbler/ks_mirror/centos7-x86_64

# Network information
# Using "new" style networking config, by matching networking information to the physical interface's
# MAC-address
%include /tmp/pre_install_network_config

# Reboot after installation
reboot

#Root password
rootpw --iscrypted $1$mF86/UHC$WvcIcX2t6crBz2onWxyac.
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  America/New_York
....

If you compare the final Kickstart and with the template sample_end.ks, you will notice the template is much shorter. This is because the template uses variables, control flow constructs and snippets to generate the final configuration. You can find the documentation about how this is done in the Cobbler Documentation. We will explain some of the syntax so you know enough about it to modify the template for our needs.

9.1. Variables

Variables come from either the global cobbler settings file or are part of the profile or system configuration. All available template variables for a specific system can be seen by running cobbler system dumpvars --name=SYSTEMNAME.

E.g. one setting is default_password_crypted, which is the root password for newly installed systems.

# contents of /etc/cobbler/settings
....
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
....

Inside our kickstart sample template this variable is used to set the password as follows:

rootpw --iscrypted $default_password_crypted

Which then is rendered as

rootpw --iscrypted $1$mF86/UHC$WvcIcX2t6crBz2onWxyac.

in the final Kickstart.

9.2. Control Flow

The Cheetah template engine allows you to use control flow constructs to insert code based on conditions or using loops. You can find more information here.

9.2.1. Conditionals

#if $foo
only add this line if variable 'foo' is defined and evaluates to true
#end if

9.2.2. Loops

#for $item in $list
add this line for each item in list
#end for

9.3. Snippets

Common tasks or reusable templates such as generating the network configuration on the installed system are placed in snippets. Cobbler provides a set of them in /var/lib/cobbler/snippets. They are included using the $SNIPPET('snippet-name') placeholder.

9.4. Validate Kickstart scripts

To validate your kickstarts and ensure you don’t have any typos you can use cobbler validateks (requires pykickstart to be installed).