Provisioning a Packer Image with Bash

15 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Packer lets us create machine images for a variety of platforms through code. Part of the image creation process involves provisioning the machine, which can be done with a variety of provisioners. At its most “basic” form, however, we can use the shell provisioner, which lets us use the machine’s default shell to run commands and scripts.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the Inline Command Provisioner

Update the packer.json file with a shell provisioner block.

NOTE: Allow an extra 2 minutes for the server build to complete upon login.

Create the Script Provisioner

Continue updating the file to include the two additional scripts. Note how we had to update the original shell provisioner, as well.

Test the Build
  1. Update the file with the provided access key, secret key, and subnet ID.
  2. Save and exit the file.
  3. Test the build.

Additional Resources

You have been tasked with building a Packer template for a new project. The resulting image build needs to provision a LAMP stack and website on an Ubuntu 20.04 server. Since there is no available configuration management available for this particular project, a series of Bash scripts have been written to complete this task.

NOTE: Allow an extra 2 minutes for the server build to complete upon login.

Two provisioner blocks will need to be created:

  • One that runs the sudo apt update -y && sudo apt upgrade -y command
  • One that runs the provided scripts in the following order:
    • Requires an environmental variable, $HOSTNAME
      • Set to bookapp01
    • Both scripts should be saved to the image in an /opt/provisioning directory.
    • This directory needs to be created.

A basic template that can provision an Ubuntu 20.04 server on AWS has been provided in the /home/cloud_user/packer/bookapp directory. Expand upon this to finish the template.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?