Goodbye PXE

Posted by Brad on Mon 18 February 2019

Every once in a while I come across a tool or technology that is not just "neat" but really cool. Ansible and Python are the most notable. And today (well a couple weeks ago by the time I wrote this) I found another, Packer. I've known about Packer for a while but never really dove into it since most of the other Hashicorp tools fell into the neat but not necessarily useful category (and what the hell is up with the configuration syntax for vagrant?). Packer uses easy to read/write JSON for its configuration so it only takes a couple hours to get up to speed. And perhaps the coolest thing Packer is capable of is the ability to type into the VM console when it's creating the VM/template. With this you can use a standard CentOS ISO to install a custom kickstart or run any sort of boot command you might want.

Previously using Katello, a kickstart install took about 15 minutes for a VM in the lab, whereas deploying a template takes about a minute. The VM template also works a lot better with Terraform(keep an eye out for a post on that soon). Katello also had poor version control(internal, not git based) and that silly Puppet style syntax for its provisioning templates. Now with Packer I can maintain my templates in git just like everything else.

Taking Packer a step further I added a gitlab CI job to trigger the template build any time I do a git push, so my template will always be up to date. You can check it out at https://git.bradlab.tech/lab/packer.

Setting up Packer

Packer itself is just a simple download and unzip and its ready (though there may be a "packer" already installed on your system to watch out for). However, the vmware provider that comes with Packer is completely crap. It only works with ESXi or VMware Workstation. Fortunately, the Jetbrains folks have made a nice provider that works with vCenter and can be found here. Simply put it in the same directory as your packer binary.

Gitlab CI

I'm just using the shell gitlab-runner so I simply set up the gitlab-runner user as I would my own workstation and we were good to go. For now the gitlab CI job is just the one liner packer command but at some point I might add a step to export the template to an nfs share for archiving.

Final Notes

So now I have a nice version-controlled and self-updating VM template for the lab. And soon I'll write a follow-up post taking this even further with Terraform.