ESXi Kickstart and automated vCenter registration

I haven’t worked on VMware for a while but needed to work on a project to automatically install ESXi on a few servers.  I invented a tool called KUBAM that was originally for deploying Kubernetes on UCS Bare Metal (KUBAM) but have realized there are a lot of people that can benefit from the use of vMedia policy installations.  I’ve written a few articles on this method here and there.

When looking to deploy ESXi we had made the kickstart portion work perfectly and even upgraded it to 6.7.  However, when looking for information on how to automatically register the ESXi servers to vCenter after the installation was concluded the best we found was information from the legendary WIlliam Lam at VMware from a post in 2011.  Here we are 7 almost 8 years later still trying to accomplish the same thing.  The problem is the post was written in 2011 and ESXi updated the version from Python 2 to Python 3 and so parts of the script don’t work.  I’ve updated it in a dirty way to make it work and checked the code into the KUBAM project.  It could use some cleaning up to make it nice like William’s python.  I may do that as time goes on.  For now here is the code:

A few notes here:

  • urllib2 was split into different urllib packages so that is no longer included
  • The top line sets the default context to not do cert checks.  Usually I find in enterprise companies there are no certs so people just accept the cert even though there is no root authority.
  • I only have IP addresses for hostnames, but if you have DNS then you will probably want to add contents from William’s script.
  • I’m pretty lazy with this and not updating the logs.  I’ll probably go back and spend some time doing that in the future if I need to.

The code is found in the KUBAM project here.

To use this code, you can include it in your ESXi Kickstart file.  An example in the same directory is here.  Notice the key are the last lines:

We put the script (renamed vcenter.py) in the ~/kubam directory of the installer.  Then as the machine boots up it grabs the file and runs the script registering itself.

The install is nice and without glamour.  It simply adds a new server to the cluster:

With my example I didn’t add another user account but I recommend it.  I also didn’t base encode the passwords but that is something you could do as well.