ESXi Host configuration script

I’ve been playing with ESXi a bit and wanted to put together an automated build of an ESXi host.  You’d think that this would be easier than automating the build of a full ESX server, but you’d be wrong.  The lack of a service console means that only remote tools are supported, so configuration is dependent upon the Remote CLI and the Perl Toolkit.  I had hoped to only need the RCLI, but found that it was a bit lacking in features & I needed the Perl Toolkit as well to get everything.  Follow on for the script & details of what it does.

You will need both the RCLI and the Perl Toolkit installed, you will also need DNS setup to resolve the ESX server FQDN.  You should be able to get the script to work by changing the environment variables at the top of the script.

The script will do the following:

  • Setup NTP
  • Setup syslog forwarding
  • Connect to some NFS datastores for VMs
  • Connect to an NFS datastore for ESX server scratch, this is required for the ESXi to join an HA cluster
  • Join Virtual Centre
  • Move into an HA & DRS cluster

The script will not yet do the following:

  • Enable VMotion (required for DRS)
  • Keep syslog forwarding going after a reboot!!
  • Configure SCSI, iSCSI or FibreChannel storage

Please let me know if you find ways of doing these.

 

@echo off
if A%1A == AA Goto Usage

rem ——————————————–
rem – set some variables
rem – update these for your environment

rem – Configuration on the ESXi Host

set DNSSuffix=embedded.local
set DNSServerList=10.1.1.1
set ESXRootPassword=vmware
set NFSServer=10.1.1.1
set NFSMounts=NFS1,NFS2
set NTPServerList=10.1.1.1
set PerlToolkitPath="C:\Program Files\VMware\VMware VI Perl Toolkit\Perl\apps"
set SyslogHost=syslog.embedded.local

rem – Configuration for Virtual Centre

set VirtualCentreClusterName="ESXi Cluster"
set VirtualCentreServer=virtualcentre
set VirtualCentreUserID=administrator
set VirtualCentreUserPassword=vmware

rem ——————————————–
rem – set script variables
rem – do not change these

set VI_USERNAME=root
set VI_PASSWORD=vmware
set VI_Server=%1.%DNSSuffix%
set Hostname=%1.%DNSSuffix%

echo **********************************************
echo *                                            *
echo *  ESXi embedded  Configuration              *
echo *                                            *
echo *  %Hostname%                    
echo *                                            *
echo *  DNS                                       *
echo *                                            *
perl %PerlToolkitPath%\rcli\esxcfg-dns.pl -D %DNSServerList% -d %DNSSuffix% -n %1
echo .
echo *  NTP                                       *
perl %PerlToolkitPath%\rcli\esxcfg-ntp.pl -a %NTPServerList%
echo .
perl %PerlToolkitPath%\rcli\esxcfg-ntp.pl -r
echo .
echo *  Syslog                                    *
perl %PerlToolkitPath%\rcli\vicfg-syslog.pl -s %SyslogHost%
echo *  connect NAS Datastores                    *
for %%S in (%NFSMounts%) do (perl %PerlToolkitPath%\rcli\vicfg-nas.pl -a –nasserver %NFSServer% –share /%%S %%S)
echo *                                            *
echo *  NAS Datastore for scratch                 *
perl %PerlToolkitPath%\rcli\vicfg-nas.pl -a –nasserver %NFSServer% –share /%1 %1
perl %PerlToolkitPath%\rcli\esxcfg-advcfg.pl -s /vmfs/volumes/%1 ScratchConfig.ConfiguredScratchLocation
perl %PerlToolkitPath%\rcli\esxcfg-advcfg.pl -s true ScratchConfig.ConfiguredSwapState
echo *                                            *
echo *  Enter Maintenance mode (throws Error)     *
perl %PerlToolkitPath%\host\hostops.pl –operation enter_maintenance –target_host %Hostname%
echo *                         (wait 5 seconds)   *
sleep 5
echo *                                            *
echo *  Reboot to apply changes (throws Error)    *
perl %PerlToolkitPath%\host\hostops.pl –operation reboot –target_host %Hostname%
echo *                         (wait 5 minutes)   *
sleep 300

set VI_USERNAME=%VirtualCentreUserId%
set VI_PASSWORD=%VirtualCentreUserPassword%
set VI_Server=%VirtualCentreServer%.%DNSSuffix%
echo *                                            *
echo * Add to Virtual centre                      *
perl %PerlToolkitPath%\host\hostops.pl –operation add_standalone -target_host %Hostname% –target_username root –target_password %VI_PASSWORD%
echo *                                            *
echo * Add to HA cluster (will take some time)    *
perl %PerlToolkitPath%\host\hostops.pl –operation moveintocluster -target_host %Hostname% –cluster %VirtualCentreClusterName%
echo *                                            *
echo *  Done with %Hostname%
echo *                                            *
echo **********************************************
Goto End
:Usage
echo **********************************************
echo *                                            *
echo *  ESXi embedded  Configuration              *
echo *                                            *
echo *  Please specify a server to configure      *
echo *                                            *
echo **********************************************
pause
:end

© 2008, Alastair. All rights reserved.

About Alastair

I am a professional geek, working in IT Infrastructure. Mostly I help to communicate and educate around the use of current technology and the direction of future technologies.
This entry was posted in VMWare. Bookmark the permalink.