As part of an internal effort to automate our Pod development process (we develop pretty large Pods that are consumed during the trainings we deliver) we started exploring some options to automate the pod build and get a consistent use case configuration. We also want to test the pod against the lab manual we give to the students, in order to avoid to fix stuff as we go :).

To achieve this, I started exploring the idea of using Vagrant and Packer to automate the process, this is something I haven’t tried before and it’s likely I will encounter some major annoyances during the journey so I thought it would be good to document every success (or failure) with a blog post.

First thing I started working on is having an ESXi 5.5 box that works with Vagrant, and possibly to build that from the official ISO using Packer, it took me a couple of nights but I managed to create a working Packer template that builds and configure an ESXi 5.5 VM from scratch, I already uploaded the template and the associated files to our packer-templates repository.

Obviously you need to supply the ESXi ISO (as there’s no way to download it directly from VMware website), this should be fairly straightforward, just change the "iso_url" and "iso_checksum" accordingly.

Also, to build this specific box with Packer, I rely on a DHCP “trick”. What happens is that Packer monitors the DHCP lease table of Fusion (or Workstation) to match the MAC in the VMX file and gather the IP address of the VM it’s building, this, of course, will not work with ESXi as the MAC address is the one associated with the pNIC, and not with the VMkernel port.

To kind of “overcome” this, and maintain DHCP all across the board, I start a single build of ESXi, during the install the initial process will fetch an IP from the DHCP pool and Packer will immediately start to SSH against this IP to no avail (as the install process is still ongoing), after the install is done and after a reboot, the vmk0 interface will most likely get the same IP it had during the install (assuming no other DHCP events occur), this will keep Packer continue the build and conclude it succesfully.

I know it’s not a real solution, but it currently works for me (it’s the typical “it works on my machine” disclaimer) and until we get a better way to deal with DHCP in Packer I guess I’m stuck with it :).

This is a Vagrantfile that suits the ESXi box, it has minor tweaks as it requires to use root instead of vagrant as the ssh user and a different shell (bash is not available on ESXi).

It’s worth repeating that as almost everything on this website, this is absolutely NOT SUPPORTED by VMware.