Efficient Proxmox Templates: A Focused Look at Packer

Rounded avatar

karakoo

Jul 5, 2025
Header image

Efficient Proxmox Templates: A Focused Look at Packer

Automating virtual machine template creation is essential for modern IT efficiency. HashiCorp Packer excels at this, allowing you to define and build identical machine images consistently.

This guide offers a focused technical look at a Packer setup for creating an Ubuntu Server 22.04 template on Proxmox VE, with Docker pre-installed.

Why Choose Packer for Building Your VM Templates?

The advantages are compelling:

  • Automation and speed: Packer automates the image creation process from OS installation to software provisioning and configuration.
  • Consistency and reliability: Every template is built the same way every time.
  • Version control: Packer configurations are text files and can be reviewed, tracked, and rolled back.
  • Multi-platform support: The same workflow can be adapted to many virtualization platforms and cloud providers.
  • Extensibility: Packer integrates with tools such as Ansible, Chef, Puppet, and shell scripts.

The Master Blueprint: ubuntu-22.pkr.hcl

packer {
  required_plugins {
    name = {
      version = "~> 1"
      source  = "github.com/hashicorp/proxmox"
    }
  }
}

source "proxmox-iso" "ubuntu-server-22-with-docker" {
  proxmox_url              = var.proxmox_api_url
  insecure_skip_tls_verify = var.tls_verify
  username                 = var.credentials["proxmox_api_token_id"]
  token                    = var.credentials["proxmox_api_token_secret"]
  iso_file                 = var.iso["path"]
  iso_storage_pool         = var.iso["storage_pool"]
  unmount_iso              = var.iso["unmount_enabled"]
  node                     = var.node_name
  template_description     = var.template_description
  vm_name                  = var.vm["name"]
  cores                    = var.vm["cores"]
  memory                   = var.vm["memory"]
  sockets                  = var.vm["sockets"]
}

This file contains the core logic for the image-building process. It defines the Proxmox builder, ISO details, VM characteristics, boot behavior, and provisioning steps.

The Definitions: variables.pkr.hcl

The variables file declares expected inputs and keeps the main configuration clean.

variable "proxmox_api_url" {
  type = string
}

variable "credentials" {
  type = map(string)
}

variable "tls_verify" {
  type = bool
}

By defining inputs clearly, you make the build easier to reuse and safer to maintain.

Your Environment Details

Packer automatically loads files ending in .auto.pkrvars.hcl. This file contains environment-specific values and should remain private.

proxmox_api_url = "https://your-proxmox-host:8006/api2/json"
tls_verify      = false
node_name       = "pve"
template_description = "Ubuntu Server 22.04 LTS with Docker"

This file injects node names, storage pools, API settings, and desired VM specifications into the build process.

Key Advantages of This Workflow

  • Reproducibility: Identical templates every build.
  • Efficiency: Less manual effort and faster delivery.
  • Versioning: Infrastructure as Code for image management.
  • Consistency: Standard base images for all deployments.
  • Scalability: Easier updates and template variations.

Conclusion

This Packer configuration provides a robust and automated method for creating Docker-equipped Ubuntu 22.04 templates on Proxmox. With clear structure, you get a maintainable workflow and the benefits of automation and consistency.

© 2025 Karakoo GmbH. All rights reserved. For any enquiry mail us at [email protected]