Packer lets us create machine images for a variety of platforms through code. Part of this involves provisioning an initial machine to match our desired state. In this hands-on lab, we use both the `file` and `shell` provisioners to prepare a Packer template for a web instance.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Add the File Provisioner(s)
Please give the lab an extra three minutes before starting the lab activity. After that, log in to the provided Ubuntu Workstation server using the credentials provided.
Note: There are multiple ways to complete this lab. We’ll be using two
file
provisioner blocks objects. You could alternatively upload the entirefiles
directory in one object and then move all files via script.Create an object to move the website files to
/var/www/html/bookapp
. Place it between the twoshell
provisioners.Add a second
file
object to move the Apache configuration to/tmp/
. Since/etc/apache2
requires elevated privileges, we’ll need to move thebookapp.conf
file from/tmp/
via shell provisioner.- Update the Scripts
We’ll need to update both the initial inline
shell
provisioner and thescripts
provisioner that follows ourfile
objects.Update the
inline
list to create the/var/www/html
directory and grantubuntu
temporary ownership of it.Then, update the
webdeploy.sh
script itself to move ourbookapp.conf
Apache configuration.- Test the Build
Return to the
packer.json
file and update the variables for access key, secret key, and subnet ID. Save and exit, and then test the build.