Packer lets us quickly and easily build machine images — at least, it does when everything works. Luckily, Packer provides us with two methods of debugging and testing our builds: the `-debug` flag and the breakpoint provisioner. In this lab, we’ll use both of these tools to troubleshoot a troublesome build.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Test Build and Troubleshoot
- Test the build.
- Proceed until the build fails.
- In another terminal session, log in to the server a second time. Look for the LXD container from this build and access it via SSH.
- Troubleshoot.
- For some reason, our file downloaded as an HTML file, not a proper gzip archive! Should we look at the file itself, we can see we’re being redirected. We can now close this window, finish our
-debug
Packer build, and take a look at our script where we download the Prometheus file. - We pull down our gzip file on line 12. The
curl
command is properly structured, and it does pull down a file, but we’ll need to add the-L
flag, which will follow any redirects. - Save and exit the file.
- Add the Breakpoint Provisioner
Before we proceed with testing our fix, we want to add one more provisioner to our
packer.json
file to test our work and ensure Prometheus is running after our provisioning step runs successfully.- Test the Build
- Run the build.
- When you hit the first breakpoint provisioner, access the Packer container and check the file type of the download.
- Stay logged in to the container as you progress to the next breakpoint, and then confirm Prometheus is working.
- Allow the build to finish.