Day 30–101 Days of DevOps — Introduction to Packer — Part 2

Welcome to Day 30 of 101 Days of DevOps. On Day 29, we have discussed the basics of Packer Let extend that concept further and dig more into Packer concepts.

To view the complete course, please check the below url.

For more info, register via the below link

YouTube Channel link

  • Create a Basic Packer Template
  • Let’s try to understand these fields.
  • The first step is to set up the environment variable
  • The second step is to validate the template and then build it
  • The next step is to build the image under debug mode. The advantage of using debug mode is packer is going to pause at each step, and you will know what the packer is doing under the hood.
  • These are the steps involved while creating AMI using packer

Packer Variables

  • Variables declaration in packer is pretty simple
  • To define a variable
  • To use it

Packer Environment Variables

  • Everything will be the same except use keyword env
  • To build it using packer

Packer Built-In Function

  • clean_ami_name
  • Timestamp
  • To use it

Provisioners in Packer

Provisioners in packer is used to install and configure the machine image after booting. Some of the common use cases for provisioners are:

  • Downloading the application code
  • Kernel patching
  • Package installation
  • Creating users

Some of the most provisioner types are:

  • File
  • Script
  • Configuration Management

File Provisioner

  • This is one of the heavily used provisioners in a packer, as this will get our files into an immutable image.
  • File provisioner also supports directory copying.

NOTE: File Provisioner is not designed to set permission, so make sure to copy your file to a temporary location and then copy it back to your desired location

  • Now run the packer build.
  • You will see something like this, uploading <file name>

Script Provisioners

  • These are OS-specific provisioner
  • The script is pretty simple here; I am trying to copy the file that was created earlier via file provisioner to the configuration(/etc) directory


Building Packer Image with Provisioners(Ansible)

  • Ansible Playbook will look like this
  • Let’s break down the code

If you like to dig deeper into the AWS concept, please feel free to check my book.

Looking forward to you guys joining this journey and spend a minimum of an hour every day for the next 101 days on DevOps work and post your progress using any of the below mediums.