Hashicorp Packer
Info
Packer Homepage | Packer Documentation | Packer QEMU Builder | Proxmox Builder (ISO) | jamlab-packer
Packer is an open source tool for creating identical machine images for multiple platforms from a single source configuration. Packer is lightweight, runs on every major operating system, and is highly performant, creating machine images for multiple platforms in parallel. Packer does not replace configuration management like Chef, Puppet or Ansible. In fact, when building images, Packer is able to use tools like Chef, Puppet or Ansible to install software onto the image.
A machine image is a single static unit that contains a pre-configured operating system and installed software which is used to quickly create new running machines. Machine image formats change for each platform.
jamlab-packer: Packer configurations for building homelab images. This repository contains my configurations for images.
Usageඞ
With the Proxmox Builder (ISO) it is possible to use a remote or local ISO file to create and configure a VM which can be converted into a template that can be used for super fast provisioning of VMs.
Commandsඞ
Install dependencies and modules:
Bash | |
---|---|
After configuring everything, building images is as easy as running a single command. PACKER_LOG=1
is used to print detailed messages while building for easier debugging:
Bash | |
---|---|
With log output to a file:
Bash | |
---|---|
Where debian11.pkr.hcl
is the configuration file that defines how to build the image.
Variablesඞ
Defining variables in HCL:
Terraform | |
---|---|
Defined variables can be used like so:
Terraform | |
---|---|
Or also substituted into other strings:
Terraform | |
---|---|
Preseedඞ
Preseeding provides a way to answer questions asked during the installation process without having to manually enter the answers while the installation is running. Read more about this method in the preseed documentation.
With preseed I configure the bare minimum for the installation to work before the cloud-init takes over.
Cloud-initඞ
Cloud-init is used for initial machine configuration like creating users, installing packages, custom scripts or preseeding authorized_keys
file for SSH authentication. Read more about this in cloud-init documentation.
With cloud-init I reset the root password to something randomized, install necessary packages for Ansible to take over the configuration and initialize the script that checks if Ansible management is bootstrapped.