Starter Scripts for ESXi Hosts: Networking and iSCSI Configuration

Background:

For years, I rebuilt my lab by clicking through the entire rebuild without a single script, let alone automation. I haven’t taken a programming class in twenty years, which was Visual Basic 6, and have shied away from PowerShell and Python until only recently. The lab was also rebuilt so often, I’m surprised I don’t mutter “enter, f11, enter, enter …” in my sleep.

Last year, I had the opportunity to learn just enough PowerShell to script the common tasks of the lab rebuild. Those scripts will be made available in our public repo on GitHub: https://github.com/humbledgeeks/amount

This post will focus on the script used to configure multiple ESXi hosts, after installing ESXi and configuring the management network for each host.

Topology:

The lab consists of two “sets” of servers and the major difference between them is their physical NIC configuration. The difference in physical NICs influences the vmnic numbering and numbering of the software initiator (vmhbaxx).

Starter Script Configure ESXi Hosts
One set of servers uses vmnic4-5 and the other set uses vmnic8-9.
Starter Script Configure ESXi Hosts
One set of servers uses vmhba64 and the other set uses vmhba66.
– Also worth noting, each host will have four iSCSI targets for discovery.
Disclaimer:

There is no guarantee the scripts will work in your environment nor a guarantee that your environment will not break when using the scripts.

If you want to use the scripts and CSV file shared, you will need to change the variables in the file to match your needs and test in a non-production environment.

Do not test in your production environment.

Script Information: “configure_hosts_new.ps1”

Note: “configure_hosts_addon.ps1″ has all the steps below, except formatting datastores with VMFS, and may be used where storage is already formatted.

  • Configure local networking:
    • Clean-up defaults.
    • Create two Virtual Machine Port Groups (VMPGs) for iSCSI and modify NIC Teaming Policy for each VMPG (only one active NIC).
    • Create additional VMPGs.
  • Create and configure storage:
    • Create two VMkernel adapters, one for each iSCSI VMPG.
    • Create and configure iSCSI software initiator.
    • Format attached datastores with VMFS.
      • Note: This step is only performed on the first host in the list. The format step will be skipped on all remaining hosts listed.
    • Rescan HBAs.
    • Rename local datastore.
  • Time
    • Configure NTP server.
    • Restart NTP service.
Walkthrough:
Starter Script Configure ESXi Hosts
You can determine your vmnic numbering in the DCUI of each host under “Management Network” > “Network Adapters”
– This will be needed to update the CSV file.
Starter Script Configure ESXi Hosts
You can determine your vmhba numbering on the Storge Adapter page for each host.
– The first number available, starting with vmhba64, will be used by the host.
– This will be needed to update the CSV file.
Starter Script Configure ESXi Hosts
The files may be downloaded from our public repo, https://github.com/humbledgeeks/amount
– Alternatively, you may use git.
Starter Script Configure ESXi Hosts
Change the password to match root credentials
– This assumes all hosts use the same password.
– Admittedly, this is a bad way to handle passwords in a script. Do not put place passwords in the file and then share in an unsecure location.
Starter Script Configure ESXi Hosts
I have four VLANs needed before vCenter is deployed and vDS is available
– To reduce the number of VMPGs created, you may comment out the line (put # in front).
– The variable names may be changed, i.e., $_.oobmpgname to $_.newname; but, you will need to update the column in the CSV file from “oobmpgname” to “newname”.
– Lines 29 to 57 apply to the first host, match changes made in this section to lines 125 to 155 for the remaining hosts.
Starter Script Configure ESXi Hosts
I have four iSCSI discovery target IP addresses
– If you have fewer discovery IP addresses, you may comment out the lines as needed.
– Lines 59 to 86 apply to the first host, match changes made in this section to lines 157 to 184 for the remaining hosts.
Starter Script Configure ESXi Hosts
Update variables in the CSV file
– Hostnames
– VMPG name for the management network; column = mgmtpgname
– Local datastore name; column = localdatastore
– vmnics to be used for vSwitch0; columns = sw0nic0 & sw0nic1
– VMPG name and VLAN ID for “Core Servers”; columns = corepgname & corepgvlan
– VMPG name and VLAN ID for iSCSI-A’s initiator; columns = iscsi1pgname & iscsi1pgvlan
– iSCSI-A’s IP address and subnet mask; columns = iscsi1ip & iscsi1sn
– VMPG name and VLAN ID for iSCSI-B’s initiator; columns = iscsi2pgname & iscsi2pgvlan
– iSCSI-B’s IP address and subnet mask; columns = iscsi2ip & iscsi2sn
– Software Initator’s vmhba number; column = vmhbax
Starter Script Configure ESXi Hosts
Continue to update variables in the CSV file
– iSCSI discovery target 1; columns = iscsitg1ip & iscsitg1port
– iSCSI discovery target 2; columns = iscsitg2ip & iscsitg2port
– iSCSI discovery target 3; columns = iscsitg3ip & iscsitg3port
– iSCSI discovery target 4; columns = iscsitg4ip & iscsitg4port
– Datastore 1; columns = ds1name & ds1path
– Datastore 2; columns = ds2name & ds2path
– Datastore 2; columns = ds3name & ds3path
Continue to update variables in the CSV file
– Datastore 4; columns = ds4name & ds4path
– Datastore 5; columns = ds5name & ds5path
– Datastore 6; columns = ds5name & ds6path
– VMPG name and VLAN ID for “OOB Management”; columns = oobmpgname & oobmpgvlan
– VMPG name and VLAN ID for “Nested Labs”; columns = nlabpgname & nlabpgvlan

Leave a Comment

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

Scroll to Top