Overview
This project rebuilds RHEL 9 and Ubuntu 22.04 VMware templates every month and deploys VMs from them. The same files work for more than one vCenter site, with one settings file per site.
The main problem it solves is templates that fall behind on patches. Each build starts from a clone, so the current template is never changed and stays available as a fallback.
Tools used
- Packer: clones the current template in vCenter and turns the finished clone into a new template
- Ansible: patches the clone, cleans it up and renames it to include the OS version
- Terraform: creates VMs from the finished template
- VMware vCenter: stores the templates and runs the VMs
How it works
- Packer clones the current template and gives the clone a temporary IP
- Ansible patches the clone and removes anything that should be unique to each server
- Packer shuts the clone down and converts it to a template, named with the OS version and build date
- Terraform deploys a test VM from the new template
- Check that the test VM has its own SSH host keys, machine ID and hostname, then destroy it
After the test passes, the new template is ready for new VMs and becomes the starting point for the next monthly build.
Step-by-step guide
All the commands are in my note: Build VMware templates with Packer, Ansible and Terraform.