Home Lab – scripted installation – Part I

I was fascinated by VCF, VLC, and other scripts, including those provided by William Lam. I decided to create my own script using PowerShell, which was a lot of fun and helped me develop a deeper understanding. I am hoping that this is the first part of many articles to come. I would like to create a script that would set up the environment for vRA with just one click, without the need to download any additional elements. I want everything to be included in the script. The first part is to prepare a prereqVM that will work as PXE, TFTP, DHCP, NTP, HTTP and DNS. And then create 4 esxi hosts with PXE variables we need to specify I’m using a standard logger as prerequisites, I use 3 modules that are automatically installed, so it is very important that we run the entire script with administrator privileges Two tools that I need at the beginning but I think also in later parts are ovf tool and VCC (VMware Customer Connect CLI) Once we have everything, we proceed to create prereqMV. I won’t copy all the code here because it will be available on GIT The script first checks if the PhotonOS file already exists in the specified location, and if not, downloads it from the specified URL. Next, the script creates a cloud-config file that specifies the configuration for the PhotonOS VM. This includes the hostname, fully qualified domain name, timezone, network settings, and commands to run on startup. The cloud-config file is then compressed and encoded as base64 for use as guestinfo data in the PhotonOS VM. The script then uses the VMware OVF Tool to deploy the PhotonOS VM to the specified ESXi host and datastore. The cloud-config data is injected into the VM using the guestinfo.userdata and guestinfo.userdata.encoding options. The script waits for cloud-init to complete and the VM to be fully deployed and configured before disconnecting from the vSphere server. This is very importand stuff as on ESXI we are not able to use all ovf properties and I don’t wanna use vcenter as not all of you have in your llabs As our machine already exists, we still need to separate our lab, which is why I use protgroup The script first connects to the vSphere server using the Connect-VIServer command and retrieves all virtual switches associated with the specified ESXi host. Next, the script checks if the specified port group already exists on the virtual switch using the Get-VirtualPortGroup command. If the port group does not exist, the New-VirtualPortGroup command is used to create a new port group with the specified name and associate it with the virtual switch. The script then waits for the port group to become accessible using a loop that checks for the port group’s existence at regular intervals. Once the port group is accessible, the script assigns it to the specified VM using the New-NetworkAdapter command and waits for the assignment to complete before logging a success message. as we have portgrupe, we set everything on the machine Then we need to prepare PXE, here is the thing that I like the least because to install ESXi with PXE we need to have syslinux in the appropriate version, which unfortunately is not so easy to achieve now, so you need a package of files that are available on my GIT so that everyone can do it download. Here you can find the link (https://github.com/vWorldLukasz/vmware/raw/main/vmware.tar) We also download the Esxi iso and put it on our prereq VM change the files with sed and create a default file for PXE We install HTTPD to place the kickstart file on it It uses unbound for the DNS service and configures NTP, I have Polish addresses set, but I think that I will add some editing functionality the last element of the whole script is the loop installation of 4 ESXi hosts that will be included in the cluster in the future and that would be it for the first part, in the second I hope to be able to deploy vcenter and router (I’m thinking about pfsense or opnsense) but everything will depend on how difficult it will be to automate. Share with: