5

I'd like to Kickstart a couple dozen RHEL6/SL6 servers. However, some of these servers are different and I don't want to create a new ks.cfg file for each class of server.

Is there any way I can generate a Kickstart file dynamically on the fly, from a template?

For example, if I append a line like this to the Kernel:

APPEND ks=http://192.168.1.100/cgi-bin/ks.cgi ip=dhcp

Then the script ks.cgi can determine what host this is (Via the MAC address), and print out Kickstart options which are appropriate for that host. I could optionally override some options by passing parameters to the script, like this:

APPEND ks=http://192.168.1.100/cgi-bin/ks.cgi?NODETYPE=production&IP=192.168.2.80

After we kickstart the server, we activate Cfengine/Puppet on this system and manage the system using our favorite Configuration Management product.

We're experimenting with xCAT but it is proving too cumbersome. I've looked into Cobbler, but I'm not sure it does this.

Update:

A roll-your-own solution is discussed in the O'Reilly book: Managing RPM-Based Systems with Kickstart and Yum, Chapter 3. Customizing Your Kickstart Install > Dynamic ks.cfg, which echos some of the comments in this thread:

To implement such a tool is beyond the scope of this Short Cut, but I can walk through the high-level design. Any such solution would mix a data store (the things that change) with a templating solution (the things that don’t change). The data store would hold the per-machine data, such as the IP address and hostname. You would also need a unique identifier, perhaps the hostname, such that you could pick up a given machine’s data. The data store could be a flat file, XML data, or a relational database such as PostgreSQL or MySQL.

In turn, to invoke the system, you pass a machine’s unique identifier as a URL parameter. For example:

boot: linux ks=http://your.kickstart.server/gen_config?host-server25

In this example, the CGI (or servlet, or whatever) generates a ks.cfg for the machine server25.

But where, oh where, is the code for ks.cgi?

Stefan Lasiewski
  • 23,667
  • 41
  • 132
  • 186
  • Interesting question. What kind of kickstart parameters are you looking to change dynamically? – Belmin Fernandez Oct 19 '11 at 00:01
  • @Beaming: I'm not sure exactly, but I think I would mostly want to change the 'class' of server with something like `NODETYPE=production` or `NODETYPE=development`. – Stefan Lasiewski Oct 19 '11 at 00:16
  • 1
    Not really an answer, but just serving up a different kickstart script based on some URL parameters is pretty trivial PHP. It might be easier to develop this yourself then find some other software to do it for you. – devicenull Oct 19 '11 at 01:42
  • @Beaming: I also think this would be useful to specify certain network configuration. e.g. a new system can get one temporary IP address from DHCP, but then kickstart will assign 'permanent' IP addresses to one or more interfaces which will be used during the next boot. – Stefan Lasiewski Oct 19 '11 at 03:36
  • 1
    @awsiv - it is *not cool* to go editing old questions with tags for the product from the company that you work for. You can and should suggest answers, and disclose your connection. Adding edits to a question looks link-whory and very very bad. – mfinni Aug 14 '12 at 01:12
  • 1
    [Cobbler's built-in system](http://cobbler.github.com/manuals/2.2.3/4/4_-_Kickstart_Templating.html) should be perfectly sufficient to the task. – Michael Hampton Oct 15 '12 at 02:06

3 Answers3

4

Since you are already using puppet, you can also take a look at Foreman for advanced kickstart templating.

Foreman uses ruby templating, allowing flexible kickstart templating.

Stefan Lasiewski
  • 23,667
  • 41
  • 132
  • 186
Not Now
  • 3,552
  • 18
  • 19
  • We're not actually using puppet (we're stuck on Cfengine 2. We are thinking of moving to Puppet, but that looks like a big task). – Stefan Lasiewski Dec 22 '11 at 16:28
  • Since you're talking about Foreman don't stop there, have a look at Katello as well for end to end systems management. – Red Tux Dec 22 '11 at 16:40
3

I have a simple proprietary solution deployed where I use PHP as the templating language and the kickstart file is generated on the fly by a PHP script on a local server.

The process to create such a thing is very simple if you know how to write kickstart files (see this Red Hat documentation if you want to learn how):

  1. Create your basic kickstart file (with some default values for the parameters you wish to "templatize").
  2. Save the kickstart to a file on your webserver with a .php extension. I use -kickstart.php
  3. Add PHP code in the kickstart file to read URL parameters and setup the correct data, then replace your default values from step 1 with the output from PHP variables

for example, replace

network --device eth0 --bootproto dhcp --hostname SOME_STATIC_HOSTNAME

with

network --device eth0 --bootproto dhcp --hostname <?php echo $hostname;?>

That's basically it.

I wanted to have pretty URLs so the boot loader says something like:

linux ksdevice=eth0 ks=http://myserver/kickstart/rhel6/networkname/servername/ks.cfg

with all the parameters specified as path elements. For that I created an .htaccess file for the Apache webserver that looks like this:

RewriteEngine On
RewriteBase /kickstart
RewriteRule kickstart/(.*) /company-kickstart.php/$1

Then the PHP script does something like this:

<?php
list($empty,$os,$envtype,$hostname,$notimportant) = 
    explode("/",$_SERVER['PATH_INFO']);
header("Content-Type: text/plain"); # important, otherwise kickstart fails
?>
# Kickstart file automatically generated by my script.
#version=<?php echo $os;?>
install
url --url=http://my.local.mirror/<?php echo $os;?>/os/x86_64
lang en_US.UTF-8
keyboard us
network --device eth0 --bootproto dhcp --hostname <?php echo $hostname;?>
# ... rest of kickstart parameters
warren
  • 18,369
  • 23
  • 84
  • 135
Guss
  • 2,670
  • 5
  • 34
  • 59
2

Cobbler supports kickstart profiles, but kickstart works very well with PHP, so you can pass parameters in your ks=... line. You may end up scripting this yourself.

ewwhite
  • 197,159
  • 92
  • 443
  • 809