Esta página se muestra en inglés. Una traducción al español está en curso.
SkillsApr 14, 2026·3 min de lectura

Packer — Automated Machine Image Building for Any Platform

Packer is HashiCorp's tool for creating identical machine images across multiple platforms from a single source. Build AMIs, Docker images, GCE images, and VMware templates in one pipeline — the standard for immutable infrastructure.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Community
Entrada
step-1.md
Comando de instalación directa
npx -y tokrepo@latest install 63c1417d-37c8-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

TL;DR
Packer builds identical machine images across multiple cloud platforms from a single HCL template, enabling immutable infrastructure.
§01

What it is

Packer is HashiCorp's open-source tool for creating identical machine images across multiple platforms from a single source configuration. It supports Amazon AMIs, Docker images, Google Compute Engine images, VMware templates, and many more builders through a plugin system.

Infrastructure engineers, DevOps teams, and platform teams use Packer to enforce consistency between development, staging, and production environments. By baking all dependencies into a machine image, you eliminate configuration drift that occurs when provisioning servers at boot time.

§02

How it saves time or tokens

Without Packer, teams either provision servers at boot time (slow, error-prone) or manually create and snapshot images (inconsistent, undocumented). Packer automates the entire process: launch a temporary instance, run provisioners (shell scripts, Ansible, Chef), capture the image, and destroy the instance. The result is a versioned, reproducible artifact.

A single packer build command replaces a multi-step manual process that typically takes 30-60 minutes of an engineer's time per image variant.

§03

How to use

  1. Install Packer:
brew install packer
  1. Write an HCL template and build:
packer init aws.pkr.hcl
packer validate aws.pkr.hcl
packer build aws.pkr.hcl
  1. The output is a machine image ID (AMI, Docker tag, etc.) ready for deployment.
§04

Example

A Packer HCL template for building an AWS AMI:

packer {
  required_plugins {
    amazon = {
      source  = "github.com/hashicorp/amazon"
      version = "~> 1.3"
    }
  }
}

source "amazon-ebs" "ubuntu" {
  ami_name      = "my-app-{{timestamp}}"
  instance_type = "t3.micro"
  region        = "us-east-1"
  source_ami    = "ami-0c7217cdde317cfec"
  ssh_username  = "ubuntu"
}

build {
  sources = ["source.amazon-ebs.ubuntu"]
  provisioner "shell" {
    inline = [
      "sudo apt-get update -y",
      "sudo apt-get install -y nginx"
    ]
  }
}

This template launches a t3.micro instance, installs nginx, and captures the result as a timestamped AMI.

§05

Related on TokRepo

  • DevOps Tools -- Infrastructure automation tools for building and deploying
  • Automation Tools -- CI/CD pipelines and build automation workflows
§06

Common pitfalls

  • Forgetting packer init before the first build. Packer 1.7+ requires explicit plugin installation via init, and builds fail without it.
  • Not cleaning up old AMIs. Each build creates a new image; set up a lifecycle policy or script to deregister images older than N days.
  • Provisioner ordering matters. Shell provisioners run sequentially; if an early step fails, subsequent steps may succeed silently with a broken base. Use set -e in shell scripts.

Preguntas frecuentes

What platforms does Packer support?+

Packer supports AWS (AMI), Google Cloud (GCE), Azure (managed images), Docker, VMware, VirtualBox, Proxmox, and many more through its plugin system. You can build images for multiple platforms simultaneously from the same template.

How does Packer relate to Terraform?+

Packer creates machine images. Terraform provisions infrastructure using those images. A typical workflow is: Packer builds an AMI, then Terraform references that AMI ID to launch EC2 instances. Both are HashiCorp tools and complement each other.

Can Packer use Ansible for provisioning?+

Yes. Packer has an Ansible provisioner that runs playbooks inside the temporary build instance. This lets teams reuse existing Ansible roles for image building without rewriting them as shell scripts.

Does Packer support parallel builds?+

Yes. You can define multiple sources in a single build block and Packer builds them in parallel. This is useful for creating identical images across AWS, GCP, and Docker simultaneously.

What is the difference between HCL and JSON templates?+

Packer supports both HCL (HashiCorp Configuration Language) and JSON templates. HCL is the recommended format since Packer 1.7, offering better readability, variables, and expressions. JSON templates are considered legacy but still supported.

Referencias (3)

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados