One of the more powerful new features in Satellite 5.3 is Cheetah based kickstart templating. With this new capability, you can include variables, snippets (see below), and flow control statements such as for
loops and if
statements in your kickstart files.
Templating allows for variables such as foo
to be defined, and the value of those variables replaced wherever $foo
is seen in a kickstart file.
Variables are subject to a form of inheritance that allows them to be set at one level and overridden at levels below them — the hierarchy is defined by Cobbler:
Kickstart tree (distro
in cobbler) parameters come first
Kickstart Profile parameters override kickstart tree parameters
System parameters override Profile parameters
If a variable is defined at the system level, it will override the same variable defined at the Profile or Distro levels. Likewise, if a variable is defined at the Profile level, it will override the same variable if defined at the kickstart tree (distro) level.
Note
Note that kickstart tree (distro) variables cannot be defined for non-custom (automatically generated) kickstart trees such as the ones you get when you do a satellite sync.
Snippets are similar to variables but can span many lines and can include variables in them. They can be included in a kickstart profile by using the text $SNIPPET('snippet_name')
. You may make a snippet for a certain package list, one for a particular %post
script, or for any text that would normally be included in a kickstart file.
The main purpose of snippets are to be able to reuse pieces of code between multiple kickstart templates and thus make each template easy to understand.
To manage snippets navigate to the Systems => Kickstart => Kickstart Snippets page. From here you can see Default Snippets that may not be edited, but may be used by any organization. These default snippets are provided to help make large tasks easier. For an explanation of common default snippets see the Default Snippet section below. From this page you may also view Snippets created just for your organization on the Custom Snippets tab. You may also create a custom Snippet by clicking on the create new snippet link. Note, default snippets are stored on the Satellite server's file system in /var/lib/cobbler/snippets/
while custom snippets are stored in the /var/lib/rhn/kickstarts/snippets/
directory. Since Satellite stores its snippets for different orgs in different directories, any custom snippets will be used like the following:
$SNIPPET('spacewalk/1/snippet_name')
The 1
in this case is the organization id. If you are not sure what text to insert in the kickstart in order to use your custom snippet, look for the Snippet Macro column on the snippet list, or on the snippet details page.
Snippets exist at a global level and do not share the same inheritance structure as variables. You may use variables within the snippets to change the way they behave depending on which system is requesting the kickstart.
5.7.3.1. Default Snippets
There are many snippets that ship by default and may be used in kickstarts written on or uploaded to the Satellite server. You may want to look at a template from a wizard style kickstart located in /var/lib/rhn/kickstarts/wizard/
and see what default snippets are used and how they are used. One of the most useful ones is redhat_register
.
The redhat_register
snippet can be used to register machines to a Satellite server as part of the kickstart. It uses a special variable called redhat_management_key to register it to the server. Simply set that variable at either the system, profile, or distro level and then add $SNIPPET('redhat_register')
to a %post section of your kickstart. Any wizard style kickstarts that are generated by the Satellite server will already include this snippet in it's pre-made %post
section.
5.7.3.2. Escaping Special Characeters
Since the $
and #
characters are used during templating for specifying variables and control flow, you should not use these characters within scripts without escaping them.
So for example, if you were writing a bash script in a %post
section:
%post
echo $foo > /tmp/foo.txt
The templating engine would try to find a variable named $foo
and would fail if foo
did not exist as a variable. There are a few ways to escape the $
symbol so it shows up as a bash variable. The simplest is with a backslash:
%post
echo \$foo > /tmp/foo.txt
\$foo
will be rendered as $foo
within the kickstart.
A second method is to wrap the entire script in #raw ... #endraw
:
%post
#raw
echo $foo > /tmp/foo.txt
#endraw
All %pre
and %post
scripts created using the wizard style kickstarts are wrapped with #raw...#endraw
by default. This can be toggled using the Template checkbox available when editing a %post
or %pre
script.
The final method is simply by including #errorCatcher Echo
in the first line of your kickstart. This instructs the templating engine to ignore any variables that do not exist and print out the text as is. This option is already included in the wizard style kickstarts, but you may want to include it in the raw kickstarts you create yourself.
If you would like more information about Cheetah and the constructs that can be used for writing kickstart templates, the Cheetah User's Guide should be very helpful: