📚
Aditya Kumar
  • About me
    • Resume
  • Automating Amazon EBS
  • ECS Bluegreen with Lambda SWAP
  • First drive of AWS Chatbot
  • Talking COVID-19 with Amazon Lex
  • Managed Jupyter on AWS SageMaker
  • Extending GitOps to reliability-as-code with GitHub and StackPulse
  • HashiCorp Packer for Machine Images
  • Deleted My Web App and App Service Plan, Whats Next ?
  • Using Terraform for zero downtime updates of an Auto Scaling group in AWS
  • Automating Instagram Posts with AI: A Step-by-Step Guide
  • Merge Commit Message Validator for Pull Requests
  • Automating Jenkins Data Backup with rsync and Slack Notifications
  • Creating a One-Time Setup for Kubernetes Cluster with Worker Nodes Using HAProxy
Powered by GitBook
On this page
  • What is Packer?
  • How is Packer different from Vagrant images ?
  • Using Packer

Was this helpful?

HashiCorp Packer for Machine Images

PreviousExtending GitOps to reliability-as-code with GitHub and StackPulseNextDeleted My Web App and App Service Plan, Whats Next ?

Last updated 4 years ago

Was this helpful?

What is 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 or Puppet.

In fact, when building images, Packer is able to use tools like Chef or Puppet 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. Some examples include AMIs for EC2, VMDK/VMX files for VMware, OVF exports for VirtualBox, etc.

How is Packer different from Vagrant images ?

If you’ve ever used Vagrant you may be thinking, what is different between Vagrant and Packer? Put simple Vagrant pulls down a pre built virtual machine from a repository or a location of your choosing and sets it up while Packer creates the virtual machine fresh from an ISO each time.

Packer can easily be used to create your own Vagrant images.

Using Packer

Packer scripts are written in JSON format as below given example:-

In each script there are four major blocks

VARIABLES:- This lets you parameterize you packer template and stores all the import variables such as region , AWS secrets , etc.

BUILDERS:- Within the template the builders section contains an array of all the builders that Packer should use to generate machine images for the template. Builders are responsible for creating machines and generating images from them for various platforms.

PROVISIONERS:- Within the template, the provisioners section contains an array of all the provisioners that Packer should use to install and configure software within running machines prior to turning them into machine images. Provisioners are optional. If no provisioners are defined within a template, then no software other than the defaults will be installed within the resulting machine images .

POST-PROCESSORS:- The post-processor section within a template configures any post-processing that will be done to images built by the builders. Examples of post-processing would be compressing files, uploading artifacts, etc. Post-processors are optional. If no post-processors are defined within a template, then no post-processing will be done to the image. The resulting artifact of a build is just the image outputted by the builder.

Create a JSON file as per the infrastructure create your own builder block as below given example and name it as quickstart.json

Now in provisioners block pass the provisioner type and the bootstrap script for the required software installation.

Now in order to validate the script to check whether the syntax and the variables used are correct or not Packer has a functionality of validating the script before build

This command will check for the syntactical and builders error in the script before build .

And then you can go on with the build.

NOTE:- PACKER CREATES ITS OWN SECURITY GROUP , AUTHENTICATION KEY AND INSTANCE IN AWS ENVIRONMENT , MAKE SURE THAT THE IAM ROLE IS CONFIGURED IN SUCH A WAY THAT IT DOES NOT CREATE ANY PROBLEM WITH PACKER OPERATIONS.

For more detailed usage visit

HashiCorp Packer
Shimla,Himachal Pradesh,India