How To Reuse Your Ansible Roles To Build Docker Images With Packer

In this article, I will show you how to reuse your Ansible roles to build Docker images using Packer.
If you are like me, you have probably used Ansible for a while. You probably have Ansible roles that you use to install and manage software on-premise and VM. Now you want to reuse those roles to build your own custom Docker images to use for development, testing, or production.

This is possible and very useful with minor changes to the Ansible roles. In fact, with Docker, you start with a very minimalistic environment and you can't take for granted some components that you will find preinstalled on major Linux distros.

How to Create a Ubuntu Packer Image and Deploy on a Bare Metal Server

In this blog post, we will discuss how you can create a minimalistic raw Ubuntu image using Packer and then deploy it on a bare-metal server using the provisioning engine, Tinkerbell.

What is Packer?

Packer by HashiCorp is an awesome tool to create pre-configured machine images which can be directly used to create an instance. This should not be seen as a replacement for other configuration tools like Ansible, Chef, etc. Instead, you can use the same tools to pre-configure your image, and with Packer, you can automate the management of your machine images like pushing to an image repository or ensuring your CI pipelines have updated images. Packer also helps you to create parallel builds, i.e you can create multiple images for different platforms using a single template. This enables you to ensure changes in your applications can be tested on multiple platforms simultaneously. It can also be seen as a factor to reduce the parity between developer and production builds.

Should We Start Baking Immutable Infrastructure Instead of Frying On-Demand?

It is an age-old dilemma that awaits me every time I walk into the chip shop. Should I go for the fried-to-order fish? Or the baked and ready-to-eat meat pie? A similar question can arise in the context of how to build infrastructure.

Photo by Laurenz Kleinheider on Unsplash

The Fried-To-Order Approach

"Frying" infrastructure on-demand is the default approach to building infrastructure. Pick up an IaC tool or two and program it to carry out the same steps as you would follow while doing a manual installation.