AMI Backing: Using Ansible to Provision with Packer

Immutable Infrastructure in on the heart of DevOps. Today Backing is a very popular idea. AWS allow you to create AMI(AMI is amazon specific image is kinda of a ISO on the OS) this image can be backed in a automated fashion. To perform this task we can use Packer but Packer will take care on the AMI and publishing to AWS but you still need to install things on this linux image lets say Ubuntu or CentOS for instance. For provision you can use Ansible.

In this post i will show how to install Ansible, Packer and build an AMI image with Packer and have the full provisioning using Ansible. 

Installing Ansible on AWS

Installing Packer

Baking AMI with Packer and Provision with Ansible

So first you need define the packer configuration. You will need create a file, let's called config.json. In this file you will provide custom variable you want yo put on the backed image, whats is the target you are building, for this case will be AMI but you can use packer to build other things like Docker containers. For last you need have the provision configuration. This config will make Packer download and install Ansible and then provision with Ansible, as you can see I'm calling a ansible playbook called Apache.yml to install Apache inside this AMI.  You also need provide a base AMI ID, you can use any AMI ID i used a very basic one with just linux on it but you can use this to create more complex and layered solutions.

Now let's check the Ansible Apache Playbook.

For last we need call Packer with all this configs, so did a simple bash script that will do the work, then you can just run $ sudo ./ and that's it. Have Fun. IF you do everything right you will get a AMI ID in the end of the build, then you can go to the AWS console and launch a EC2 instance based on this AMI ID and will work :-)
Diego Pacheco

Popular posts from this blog

Podman in Linux

Java Agents

Manage Work not People