Build your Proxmox templates with packer
In the world of virtualization and infrastructure as code (IaC), automating the creation of virtual machine templates is a critical time-saver. This article introduces my open-source project that uses HashiCorp Packer to create standardized VM templates in Proxmox Virtual Environment (PVE).
The Problem with Manual Templates
Creating VM templates manually in Proxmox is time-consuming and error-prone. Each time you need a new template, you must:
- Download the ISO
- Create a new VM
- Install the operating system
- Configure basic settings
- Convert to template
This process becomes tedious when managing multiple distributions or versions, and it's difficult to ensure consistency.
Enter Packer Proxmox Templates
The Packer Proxmox Templates - https://github.com/unixworld-org/packer-proxmox-templates - project automates this entire workflow. With a single command, you can build ready-to-use VM templates for popular Linux distributions.
Currently Supported Operating Systems
- AlmaLinux 8
- AlmaLinux 9
- Ubuntu 22.04 LTS
- Ubuntu 24.04 LTS
How It Works
The project uses HashiCorp Packer with the Proxmox builder plugin to:
- Connect to your Proxmox server via API
- Create a temporary VM
- Boot from the specified ISO
- Perform automated installation using kickstart (AlmaLinux) or cloud-init (Ubuntu)
- Install essential packages and apply basic hardening
- Convert the finished VM to a template
Key Features
- Fully automated: No manual intervention required
- Standardized templates: Consistent configuration across all templates
- Customizable: Easy to modify variables for your environment
- SSH key authentication: Pre-configured with your SSH public key
- Makefile interface: Simple commands to build specific or all templates
Getting Started
Prerequisites
- Proxmox VE server (6.x or newer)
- API token with appropriate permissions
- ISO files uploaded to your Proxmox storage
- Packer installed on your workstation
Quick Setup
- Clone the repository:
git clone https://github.com/unixworld-org/packer-proxmox-templates
cd packer-proxmox-templates
- Configure your environment:
Make sure that you follow the full guide from the README.md file in the repository.
- Build a template:
make ubuntu2404
Best Practices for Template Management
When using this project, consider these best practices:
- Version control your configurations: Store your customized variable files in a private repository
- Use environment variables for secrets: Avoid committing API tokens or passwords
- Create separate templates for different use cases: Development, testing, and production may have different requirements
- Regularly update templates: Schedule rebuilds to incorporate security updates
Under the Hood
The project structure organizes templates by distribution and version:
├── Makefile # Contains build commands
├── variables.pkrvars.hcl # Common variables
├── almalinux8/ # AlmaLinux 8 template files
├── almalinux9/ # AlmaLinux 9 template files
├── ubuntu2204/ # Ubuntu 22.04 template files
└── ubuntu2404/ # Ubuntu 24.04 template files
Each distribution folder contains:
- Packer template definition
- Kickstart or cloud-init configuration files
- Any additional scripts or configurations
Conclusion
This is a simple template creation process for Proxmox templates using Packer. In addition to executing shell commands, Packer also supports running full Ansible playbooks, which can help you customize the templates to suit your needs. If you're interested, I can expand the project and provide some examples.