Deploy VCSA via PowerShell

I’ve been spending a lot of time lately thinking about how organizations can provide services can operationalize the principles behind Infrastructure as Code in a way that’s accessible. In my experience, if a tool isn’t easy to use, it won’t be used. This is one of the biggest barriers to organizations (and companies that provide services, like mine) benefiting from IaC. It’s my intention that this script will achieve a high level of usability and will also generate and consume reusable code for future use.

Recap

Challenge

You want to use Infrastructure as Code principles to deploy your vCenter Server, but you want to ensure that your solution is accessible without code as well.

Solution

Create a script that gathers all relevant information for a VCSA deployment via the the vcsa-deploy and generates the JSON file that the utility consumes, while also allowing for the download of the VCSA ISO from a web server.

Background

In order for this to fit my definition of infrastructure as code, we should be able to define all details of the vCenter in a structured format. Additionally, we should not assume that the vCenter installer is local, and should pull it from an external location if we need it to. While the vcsa-deploy utility can handle the installation of the vCenter, I’ve found most people don’t like it.

With this script, I allow a VI admin to fill out all relevant details of the vCenter in a spreadsheet. The script will then access the spreadsheet directly, and generate the JSON file used by vcsa-deploy. As a bonus, it will call the vcsa-deploy utility and kick off the actual deployment.

Screenshot of the excel file on my GitHub account.

Demo

Quick demo – the installer up to where it deploys the VCSA

Features

  • Validate Password Complexity
  • Provide Input via Excel Spreadsheet or JSON file
  • Download ISO, extract contents
  • Deploy vCenter to either ESXi or vCenter

Requirements

  • ImportExcel module
  • 7-zip
  • URL to a vCenter Server 6.7 Appliance ISO
  • Standard vCenter Prerequisites (forward/reverse DNS, space, networking, etc) (link)

Code Review

The code can be located on my github account. As per usual, let’s go through the code.

Lines 1-31
Documentation

Lines 32-58
Define parameters

Lines 66-91
Download and install the ISO

Lines 93-130
Extract the ISO using 7-zip

Lines 133-139
Use import-excel to grab sections of the spreadsheet. There’s a bit of overhead, but my goal here was for the spreadsheet to look good.

Lines 141-152
Validate the password specified meets VMware’s requirements for the VCSA

Lines 154-172
Detect the OS

Lines 176-224
Determine whether we are deploying to a vCenter or an ESXi host and create the respective JSON. This is the only difference between deploying to a vCenter or an ESXi host.

Lines 226-298
Create a hashtable used for to create the rest of parameters common to a the json used by vcsa-deploy.

Lines 300-312
Write the JSON file to disk

Lines 314-333
Begin the install

Lines 335-343
Determine if the install was successful. If it failed, print out the error messages.

Code

What’s next?

Good question! vSphere 7 is releasing vCenter Server Profiles and Image Cluster Management. Creating tools that can consume these new features will be helpful.

I’m working on template management using Hashicorp’s Packer and will be posting some of my work on that soon. In addition, I have done some work on Hashicorp’s Terraform for deploying lab VMs that I’ll share too. Finally – I’ve got a few skeleton Ansible Playbooks that I’m working on for configuration of the lab VMs, as well as a playbook for doing high level configuration of a bare vCenter. So in short – lots more coming!

Thanks for viewing,
Jon

One thought on “Deploy VCSA via PowerShell

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright VirtJunkie.com © 2020