Customising the kickstart script for ESXi automated installs

After my last post, ‘Installing VMware ESXi via PXE’, I found that I needed to do a little customisation of the kickstart script on a per host basis. This post shows how I went about that, with a simple hack to aquire the MAC address and then customise the script based on that. This is a very simple example, but you could modify this easily for your needs. Notice I have two MACs per host below, this is because the machines could PXE over either of their 2 interfaces.

<?php

$ipAddress=$_SERVER['REMOTE_ADDR'];
$macAddr=false;

#run the external command, break output into lines
$arp=`/usr/sbin/arp -n -a {$ipAddress}`;
$lines=explode("n", $arp);

$macMap = array(
        'b8:ac:6f:8b:9a:29' => array('ip' => '192.168.111.110', 'hostname' => 'port-110.timico.vmtest'),
        'b8:ac:6f:8b:9a:2a' => array('ip' => '192.168.111.110', 'hostname' => 'port-110.timico.vmtest'),

        'b8:ac:6f:8b:9a:4d' => array('ip' => '192.168.111.111', 'hostname' => 'port-111.timico.vmtest'),
        'b8:ac:6f:8b:9a:4e' => array('ip' => '192.168.111.111', 'hostname' => 'port-111.timico.vmtest'),

        'b8:ac:6f:90:2e:40' => array('ip' => '192.168.111.112', 'hostname' => 'port-112.timico.vmtest'),
        'b8:ac:6f:90:2e:41' => array('ip' => '192.168.111.112', 'hostname' => 'port-112.timico.vmtest'),
);

$networkConfig = 'network --bootproto=dhcp --device=vmnic0';

foreach($lines as $line)
{
   $matches = array();
   if (preg_match('/.* at ([^ ]+).*/', trim($line), $matches))
   {
     if (array_key_exists($matches[1], $macMap))
     {
       $networkConfig = sprintf('network --bootproto=static --device=vmnic0 --ip=%s --gateway=%s --netmask=%s --hostname=%s --nameserver=%s',
         $macMap[$matches[1]]['ip'],
         '192.168.111.1',
         '255.255.255.0',
         $macMap[$matches[1]]['hostname'],
         '192.168.111.101'
       );
     }
   }

}


echo <<
	

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.