Build your Proxmox templates with packer

Build your Proxmox templates with packer
Photo by Ilya Pavlov / Unsplash

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:

  1. Download the ISO
  2. Create a new VM
  3. Install the operating system
  4. Configure basic settings
  5. 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:

  1. Connect to your Proxmox server via API
  2. Create a temporary VM
  3. Boot from the specified ISO
  4. Perform automated installation using kickstart (AlmaLinux) or cloud-init (Ubuntu)
  5. Install essential packages and apply basic hardening
  6. 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

  1. Clone the repository:
git clone https://github.com/unixworld-org/packer-proxmox-templates
cd packer-proxmox-templates
  1. Configure your environment:

Make sure that you follow the full guide from the README.md file in the repository.

  1. Build a template:
make ubuntu2404

Best Practices for Template Management

When using this project, consider these best practices:

  1. Version control your configurations: Store your customized variable files in a private repository
  2. Use environment variables for secrets: Avoid committing API tokens or passwords
  3. Create separate templates for different use cases: Development, testing, and production may have different requirements
  4. 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.