Setting up HashiCorp Packer with Proxmox Part 2: Build a Baseline Patch Virtual Machine Image using Clone VM
In Part One, I walked through how to use Packer with Proxmox to set up an Ubuntu 22.04 VM image, leveraging the proxmox-iso builder to install from Ubuntu installation media.
This process, while effective, is not for the faint of heart — it involves a lengthy installation that can take up a significant amount of time. Now, in Part Two, I’ll demonstrate how to create a more traditional baseline image (by public cloud standards) using the proxmox-clone builder.
IMAGE Layered Proxmox Packer Builds starts with ISO and ends with easy-to-update baseline image
This approach offers a streamlined way to maintain and patch your image regularly, without having to go through the long process of building from installation media each time.
Once established, this baseline image will serve as the foundation for all future images in my Proxmox environment. The main benefit here is time savings — you no longer need to endure the long wait associated with installation media, giving you a reliable, up-to-date baseline image to quickly clone and adapt for other — more pressing — needs, you know — like Minecraft.
It’s Packer Time
I’m going to setup my input variables a bit different this time. Because we are building ontop of another virtual machine image and not using installation media, I need to specify the source image name. This is very similar to the process we use on the public cloud. If you are building your first image on Azure you are likely going to be referencing a Marketplace image. The proxmox_node and image_storage_pool both serve the function of simply triangulating what Proxmox Data Center and storage pool the source image is stored on. In the case of my home lab, I, of course, only have one Data Center and as we saw in my setup details in the previous chapter, only one storage pool. I suppose I could configure my Synology NAS volume as a storage pool where VM images could be stored by adding it to the supported Content Types but I haven’t looked into that yet.
Like previously, I need to specify a destination image name and versioning scheme. Previously I used a semantic versioning scheme (e.g. v1.0.0) but with this baseline image, it matters more to me what date the image was built — as that will indicate the age of the patches installed.
source_image_name = "u2204-baseline-v1.0.0"
image_storage_pool = "local-lvm"
proxmox_node = "pve"
destination_image_name = "u2204-baseline-with-updates-v2024-06-20"
Now to configure the builder. This is a heck of a lot simpler than when I used installation media. It’s probably the easiest game of connect-the-dots I’ve played in a while. Besides all the hardware specifications and SSH configuration boilerplate, it’s essentially just saying “Start with this image, produce a new image here”.
source "proxmox-clone" "ubuntu" {
clone_vm = var.source_image_name
node = var.proxmox_node
memory = 4096
cores = 2
sockets = 2
ssh_timeout = "60m"
ssh_username = "ubuntu"
ssh_password = var.admin_password
ssh_port = 22
insecure_skip_tls_verify = true
vm_name = var.destination_image_name
}
So what are we going to do on this image? Not a whole lot. Remember, this is a Packer template that I want to quickly create an image with the latest patches on it. So I want to be able to run it over and over again — possibly everyday. That way, as I build other images, I can continually roll in the patches to them simply by starting from the latest version of this image. MinecraftOps here we come!
build {
sources = [
"source.proxmox-clone.ubuntu"
]
provisioner "shell" {
execute_command = local.execute_command
inline = [
"while fuser /var/lib/apt/lists/lock >/dev/null 2>&1; do echo 'Waiting for other apt-get process to finish...'; sleep 5; done",
"while fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do echo 'Waiting for other dpkg process to finish...'; sleep 5; done",
"apt-get update",
"apt-get upgrade -y"
]
}
}
Conclusion
In conclusion, building a baseline patch image with Packer and the proxmox-clone builder offers a more efficient approach to managing multiple Virtual Machine images in your Proxmox environment. This method significantly reduces the time it takes to set up new images, allowing you to avoid the lengthy installation process from scratch using the installation media (direct from ISO). By establishing a baseline image that can be patched and updated easily, you’ll have a reliable foundation to clone and use for other, more fun, purposes — like Minecraft. This will keep your environment up to date and simplifies the ongoing maintenance of your virtual machines, making it a practical solution for regular Virtual Machine image management — even in your home lab.