After manually installing Nomad, Docker, Git, and ZSH on 3 EC2 instances, it was time to see if Packer could automate the process for me.
Last Time On
Dragon Ball Z HashiCorp Tooling
In a previous exploration with Nomad, I left a to-do item for myself to explore Packer, and this afternoon I got around to exactly that.
I had previously ran a set of repetitive commands to install
some other software on the 3 EC2 instances for my Nomad cluster.
I’m never doing that again!
Packer to the rescue. Packer is used to create machine images, which are what EC2 instances are based on.
Most relevant to my case, Packer has a feature called
which can be used to install packages on a machine image.
Just Show Me The Code
Ok, ok. Here's the
hcl file that I used with Packer.
This creates an ARM AMI, named
packer-arm and uses the
Shell Provisioner to
Build and Publish the AMI
Running Packer looks like this:
What Packer does feels like heating up a TV dinner in the microwave. A few minutes of magic and voila... A fresh new AMI is created in your AWS account.
Note: AWS credentials will need to be present in the environment for Packer to be able to create the AMI on your AWS account.
Verify the AMI
I ran a quick sanity check to verify that the software was really installed, kind of like checking that the refrigerator light shuts off when you close the door.
- Launch a new EC2 instance using the AMI that Packer created.
- SSH into the instance.
I now have a reusable machine image that I can use to launch new Nomad clients (or something else) in the future, with no manual software installation necessary!
That’s it for this post. Short and sweet like I promised.
Tune in next time for more
Dragon Ball Z1 HashiCorp tooling.
In case you don’t get the Dragon Ball Z joke... https://www.youtube.com/watch?v=x25uJOqRCXU ↩