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.
wojan says
William,
Most valueable blog post as all you share on the Web. And the quality is one of the best!
BTW, can you tell me which tool are you using to insert into your blog the above kickstart file text with all the nice fetures it brings (copy/line numlbers toggle, new window etc...)?
Thanks
William Lam says
Thanks for the kinds words!
I'm using Crayon Syntax Highlighter WP plugin
sunil patil says
Hi William, hope you are good, so nice scripting on Virtualization tech, hope you are very familiar about how to perform scripting installation over more than 100 ESXI hosts, please let me know if so, many thanks! in advance
Tiran Efrat says
Hi William,
will this ks work for vsan 6.2?
thx.
William Lam says
Yes, there maybe couple of changes required depending if you're doing an all-flash but core of the KS is still applicable
Bee Kay says
And for the newbie - how does one identify 1) if they even have VSAN available to them? and 2) What version is running/available?
pzi123 says
Judging from your diligence and devotion to automation a strange silence on the ESXi 6 is suspicious π
Have you had any luck with kickstarting ESXi 6?
I see a general failure of ESXi 6 kickstart with infamous "No NIC found with MAC address ..." reported widely with no responses from VMware gurus.
see: https://communities.vmware.com/thread/545001?start=0&tstart=0
William Lam says
There's no changes from a Kickstart standpoint between 5.5/6.0, so its not needed. Also, I don't have infinite amount of time to cover every single topic π Kickstart for 6.x works and haven't had any issues and this is true for 6.5 as well
pzi123 says
This is all I wanted to hear - I assume you have no issues kickstarting nested ESXi 6u2 with basic E1000E Ethernet interface. I and others tried that and other common hardware combinations of Ethernet with the same result. Can somebody in this blog confirm that they succeeded in nested or other ESXi kickstart in vSphere 6u2.
Logan says
William, I'm curious if you have an updated script for VSAN 6.6 or higher on ESXi 6.5 or higher?
William Lam says
Thereβs no changes to how KS works in newer releases π
Logan Spencer says
Apologies... I wasn't referring to the KS portion, but rather the VSAN portion at the very bottom (line 61 and onward). As this article was written in 2014, and references earlier versions, I'm wondering if you have updated it to reflect the new (6.6+) commands, as referenced within this post: https://www.williamlam.com/2013/09/how-to-bootstrap-vcenter-server-onto_9.html
I've got my ESXi and Windows DNS/AD bootstrap working flawlessly, but the only break I have yet to solve is the ability to have my windows VM programatically deploy the VCSA via the JSON config file AND do so on top of a VSAN datastore. Any help would be appreciated! If you'd prefer email, I can be reached at *protected email*
Thank you in advance!