Create identical machine images for multiple platforms from a single configuration
In this HashiQube DevOps lab, you will get hands-on experience with HashiCorp Packer.
Packer is an open source tool for creating identical machine images for multiple platforms from a single source configuration. It's lightweight, runs on every major operating system, and is highly performant, creating machine images for multiple platforms in parallel.
In this lab, Packer will build a Docker container, use the Shell and Ansible provisioners, and Ansible will connect to Vault to retrieve secrets using a Token.
Keeping track of base images can be challenging. HashiCorp Co-Founder and CTO Armon Dadgar explains how HCP Packer forms the core of a multi-cloud golden image pipeline.
HCP Packer, part of the HashiCorp Cloud Platform, provides a registry that tracks your image metadata and presents it to downstream processes through an API. Together with the Packer data source in the HCP provider for Terraform, this forms the foundation of a multi-cloud golden image pipeline to automate the lifecycle of images from build through deployment.
Packer Templates can be found in these directories:
packer/packer/linux
packer/packer/windows
You can build local Windows and Ubuntu boxes with Packer using these steps:
-
Navigate to the Packer directory:
cd packer
-
Run the build script:
./run.sh
Packer uses the HashiCorp Configuration Language (HCL), designed to allow concise descriptions of the required steps to get to a build file.
packer/linux/ubuntu/ubuntu-2204.pkr.hcl
[filename](packer/linux/ubuntu/ubuntu-2204.pkr.hcl ':include :type=code')
packer/windows/windowsserver/windows-2019.pkr.hcl
[filename](packer/windows/windowsserver/windows-2019.pkr.hcl ':include :type=code')
The packer.sh
script handles the installation and configuration of Packer:
[filename](packer.sh ':include :type=code')
Packer integrates with several other HashiCorp and third-party tools:
-
Vault: For secrets management
-
Ansible: For configuration management