Automation

Getting Started with Packer and VMware vSphere

Automation is the key to success in today’s fast paced world of hybrid infrastructure. Gone are the days of spending hours or days on build processes and infrastructure engineers holding up any part of the development pipeline. Today’s world of DevOps and public cloud infrastructure has necessitated operations adopting the mindset of infrastructure as code. There are so many great tools available out there to get your feet wet with automation. From PowerShell, Python, Ansible, and many other languages and configuration management tools, there are many great skills you can pick up today fairly easily. I have had as my goal to sharpen my automation skills and at least become familiar with the tools and utilities that are available for use in cranking out infrastructure with code. This allows all the great benefits such as versioning, using code repositories such as Git, testing, and many others. A tool that you see mentioned and referenced by a number of automated solutions for cranking out virtual resources such as virtual machines, templates, and others whether it be vSphere or AWS, is packer. Packer is a great tool that allows automated provisioning. In this post, we will take a look at getting started with Packer and VMware vSphere. If you have a lab and can play around with packer and creating automated builds, it is a great learning process.

Getting Packer and vSphere Provisioner Installed

The great thing about Packer and the plugins you need is they are free. These are totally free tools that are free to download and start using immediately. Let’s talk about how you get these small components configured to get started automating your VMware build processes.

What you need and where you get them:

Packer is made by a company called Hashicorp, which most of you have no doubt heard about with the likes of Terraform, etc. At the time of this writing, the latest version of Packer is 1.3.5. It uses a single executable (along with some plugins for vSphere) to fully automate builds in your environment. It does this by using JSON files to feed in the needed details about your environment and how to interact with your provisioner as well as how to customize the resulting machine.

Hashicorp-Packer-is-a-phenomenal-tool-that-allows-automating-your-build-processes
Hashicorp Packer is a phenomenal tool that allows automating your build processes

Packer is available on all the major platforms which makes it extremely versatile.

Packer-is-available-for-all-major-platforms
Packer is available for all major platforms

I am downloading Packer on a Windows 10 Professional x64 workstation. It will download as a zip file. Extract the folder wherever you want to. It can be read from anywhere and we will show how to add it to the PATH variable in Windows 10 so it can be called from any context in the command line.

Extract-the-downloaded-zip-file-containing-Packer
Extract the downloaded zip file containing Packer

Navigate to your environment variables and Edit the PATH variable. This is found under your system properties – sysdm.cpl.

Edit-your-Windows-PATH-environment-variable-to-include-the-path-to-packer
Edit your Windows PATH environment variable to include the path to packer

Click the New button to make a new entry.

Create-a-new-PATH-entry-in-your-Windows-10-PATH-variable
Create a new PATH entry in your Windows 10 PATH variable

Here I have copied the extracted packer folder to my C:Program Filespackerio folder. So, I am adding this folder to the PATH.

After-adding-packer-path-to-the-PATH-variable-in-Windows-10
After adding packer path to the PATH variable in Windows 10

To test out both Packer and the PATH statement, I am simply typing packer at the command line, without changing to the packer directory. As you can see below, the executable is properly found and we have the command line options displayed.

Testing-the-environment-variable-entry-and-executing-packer
Testing the environment variable entry and executing packer

Now for the two plugins for Packer that allow interacting with VMware environments. As you can see, the vsphere-clone and vsphere.iso are available for various platforms. Since I am using Windows, here I will download both the .exe files.

Dowloading-the-Jetbrains-Packer-plugins-for-VMware

Here, I simply place the two downloaded vsphere plugin files inside the Packer directory.

Placing-the-vsphere-plugin-files-in-the-Packer-directory-in-Windows
Placing the vsphere plugin files in the Packer directory in Windows

Just a note on the behavior you will see if you try to use a Packer template that requires the vsphere-iso plugin, you will see the following error:

Error missing the vsphere iso plugin in packer
Error missing the vsphere iso plugin in packer

Getting Started with Packer and VMware vSphere

There are so many great resources on the web for getting started with Packer and vSphere, however, Cody DeArkland has a great blog post detailing how to get a fully automated Ubuntu 18 VM build going in your vSphere environment using Packer. In fact, this post was part of the inspiration of this post for me personally getting up and running with Packer. Cody has a great Git repo that you can clone, make a few changes in the variables.json file for your specific vSphere environment, and see the automated build of Ubuntu 18 happen right before your eyes. I highly recommend checking his resources out. There are many others out there as well if you are looking for a specific template, most likely someone has already posted it or something close enough that you can use with only minor tinkering.

This is a great place to start – getting your feet wet with Packer and using someone else’s templates to see how it is supposed to work. Then as you are more familiar with the underlying mechanisms, files, etc, you can start hacking and playing around with the files yourself, customizing the builds to suit your needs and so forth. After all, isn’t this how most of us learn? Breaking stuff on purpose is one of the best ways! 🙂

Wrapping Up

Packer is an awesome tool. I am looking to use it in the home lab very heavily once I get the templates I need lined out. Automating these types of build processes provides extremely heavy lifting, easily. Imagine, always having the latest Windows build fully patched and ready to go at a moments notice – you can do that with Packer. So many other use cases as the sky is the limit with this handy little tool.

Subscribe to VirtualizationHowto via Email 🔔

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com and has over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, Brandon has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family.

Related Articles

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.