In my lab, when I need to provision a new or rebuild an existing ESXi host, I still prefer to use the true and tried method of an unattended/scripted installation also known as Kickstart. Below is a handy ESXi 5.5 Kickstart that I have been using to setup a basic VSAN environment. I figure this might come in handy for anyone looking to automate their ESXi 5.5 deployment and include some of the VSAN configurations like creating a VSAN Disk Group or enabling VSAN Traffic type on a particular VMkernel interface. For more details about this Kickstart, refer to the bottom of the file where I break down the file in more detail.
# Sample kickstart for ESXi 5.5 configuring VSAN Disk Groups # William Lam # www.virtuallyghetto.com ######################################### accepteula install --firstdisk --overwritevmfs rootpw vmware123 reboot %include /tmp/networkconfig %pre --interpreter=busybox # extract network info from bootup VMK_INT="vmk0" VMK_LINE=$(localcli network ip interface ipv4 get | grep "${VMK_INT}") IPADDR=$(echo "${VMK_LINE}" | awk '{print $2}') NETMASK=$(echo "${VMK_LINE}" | awk '{print $3}') GATEWAY=$(esxcfg-route | awk '{print $5}') DNS="172.30.0.100" HOSTNAME=$(nslookup "${IPADDR}" "${DNS}" | grep Address | grep "${IPADDR}" | awk '{print $4}') echo "network --bootproto=static --addvmportgroup=true --device=vmnic0 --ip=${IPADDR} --netmask=${NETMASK} --gateway=${GATEWAY} --nameserver=${DNS} --hostname=${HOSTNAME}" > /tmp/networkconfig %firstboot --interpreter=busybox vsan_syslog_key = "VSAN-KS" logger $vsan_syslog_key " Enabling & Starting SSH" vim-cmd hostsvc/enable_ssh vim-cmd hostsvc/start_ssh logger $vsan_syslog_key " Enabling & Starting ESXi Shell" vim-cmd hostsvc/enable_esx_shell vim-cmd hostsvc/start_esx_shell logger $vsan_syslog_key " Suppressing ESXi Shell Warning" esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1 logger $vsan_syslog_key " Reconfiguring VSAN Default Policy" esxcli vsan policy setdefault -c vdisk -p "((\"hostFailuresToTolerate\" i1) (\"forceProvisioning\" i1))" esxcli vsan policy setdefault -c vmnamespace -p "((\"hostFailuresToTolerate\" i1) (\"forceProvisioning\" i1))" logger $vsan_syslog_key "Enabling VSAN Traffic on vmk0" esxcli vsan network ipv4 add -i vmk0 # assign license vim-cmd vimsvc/license --set AAAAA-BBBBB-CCCCC-DDDDD-EEEEE %firstboot --interpreter=python import commands, os, uuid, syslog vsan_syslog_key = "VSAN-KS" debug = False # Build VSAN Disk Group command based on vdq -q output def createVsanDiskGroup(): vdqoutput = eval(commands.getoutput("/sbin/vdq -q")) md = [] ssd = '' for i in vdqoutput: if i['State'] == 'Eligible for use by VSAN': if i['Reason'] == 'Non-local disk': syslog.syslog(vsan_syslog_key + " Setting enable_local and reclaiming " + i['Name']) if debug == False: os.system("esxcli storage nmp satp rule add -s VMW_SATP_LOCAL -o enable_local -d " + i['Name']) os.system("esxcli storage core claiming reclaim -d " + i['Name']) if i['IsSSD'] == '1': ssd = i['Name'] else: md.append(i['Name']) diskgroup_cmd = 'esxcli vsan storage add -s ' + ssd + ' -d ' + ' -d '.join(md) syslog.syslog(vsan_syslog_key + " Creating VSAN Disk Group using SSD: " + ssd + " MD: " + ', '.join(md)) if debug == False: os.system(diskgroup_cmd) # Create VSAN Cluster (required only for first ESXi node) def createVsanCluster(): # generate UUID for VSAN Cluster vsan_uuid = str(uuid.uuid4()) syslog.syslog(vsan_syslog_key + " Creating VSAN Cluster using UUID: " + vsan_uuid) if debug == False: os.system("esxcli vsan cluster join -u " + vsan_uuid) createVsanDiskGroup() createVsanCluster()
If you would like to see more details on creating ESXi Kickstart, make sure to check out my ESXi 4.x & 5.x examples here.
Line 6-9 This is generic Kickstart configurations specifying EULA, how to install, password, etc. You can refer to VMware's scripted install documentation.
Line 11-25 This extracts the DHCP IP Address (static allocation) and re-creates the network configuration in Line 25 for statically assigning the IP Address to the ESXi host
Line 27 This starts the firstboot script and assumes "Busybox" as the interpreter which means basic shell commands
Line 30 I create a custom key which will be logged in syslog for our installation
Line 32-41 Basic ESXi configurations leveraging vim-cmd and ESXCLI
Line 43-45 Configure the VSAN default storage policy, please refer to this article for more details.
Line 47-38 Configure the VSAN Traffic type on vmk0
Line 35 This starts a second firstboot script, but now using "Python"
Line 50-51 Assign a license to ESXi host
Line 53 Importing the appropriate libraries that will be used in the Python script
Line 58 Using the same custom key that I created earlier for logging to syslog
Line 61-81 A method for creating VSAN Disk Group by inspecting vdq CLI and marking disks as local
Line 83-90 A method for creating VSAN Cluster, please refer to this article for more details.
Line 92-93 Invoking the two Python methods. You can either create a custom Kickstart for your "first" ESXi node if you decide to bootstrap your VSAN Cluster onto a single ESXi host. You can also use custom boot options to specify whether the ESXi host being provisioned is the first or additional nodes. This topic is a bit advanced, but if you are interested, take a look at this article here.