Kickstart: Serve dynamic kickstart images via a CGI or PHP script?
Solution 1:
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.
Solution 2:
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):
- Create your basic kickstart file (with some default values for the parameters you wish to "templatize").
- Save the kickstart to a file on your webserver with a .php extension. I use -kickstart.php
- 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
Solution 3:
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.