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

6 thoughts on “Deploy VCSA via PowerShell

  1. Interesting. There are few points which I would like to highlight.
    1. deploying VCSA using this method where there is no internet to download.
    2. Instead internet download, how about specifying alternative intranet locations such as FTP / NAS?
    3. The script developed based on linux environment, Windows version would much helpful

    1. Hey @KKrishna, thanks for stopping by.

      Re: #3 – You’re spot on.. I did use Linux to develop this, but it doesn’t make a difference. Just specify Windows paths to the 7-zip binary and your excel file and the rest should be fine.

      For #1, I actually designed this to run without internet access. An example for how to do this is here: https://www.virtjunkie.com/poor-mans-autodeploy/#Web_Server

      For #2, love the idea of pulling via FTP. I’d welcome a PR here: https://github.com/jonhowe/Virtjunkie.com/tree/master/VCSA-AutoDeploy

  2. Thanks for your prompt response.
    Unfortunately. I’m new to PS and as well Git. But I liked your approach. For me, I’m looking for script that start from place where ISO already extracted. So of now I’m trying to tailor your script.

  3. Hi – Great script! Nonetheless I’m pondering a bit why you don’t only extract the ova from the ISOvcsa and deploy using “ovf-tool”. Do you have any specific reason you could share?

    1. Good question Cristoph! I typically use ovftool when I deploy vCenter using ansible, but in this case, I wanted to use the tool that VMware provided, vcsa-deploy.

Leave a Reply

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

Copyright VirtJunkie.com © 2020
Click to access the login or register cheese