When Should I Use Ansible Versus Packer or Terraform?
I was having a conversation with a colleague recently. We were discussing DevOps, and the topic of Ansible came up as I was advocating it as a great tool to get things done.
Here’s what he had to say…
“I’ve tried using Ansible a few times and this is what I found with it.
It is great for what it does. It’s wonderful to be able to spin up a new app or web server automatically. However, what I have found for my needs is …
It is easier to build a piece of furniture than it is to explain all the steps required for someone else to build it. Or in order to replicate the steps automatically.
With cloud servers, it’s enough, for me that I’ve built it once. When I need to spin up another, I simply clone the working copy.”
My thoughts are below.
When Is Terraform Good?
Terraform is a coss-platform infrastructure building tool. If you need an IAM user or S3 bucket, Terraform can create it. Need an ec2 instance of a particular type, deployed with an autoscaling group TF is a great tool for that.
With Terraform you can capture in code, everything about your application stack, so that you can standup a complete copy in another region, that’s powerful!
Read: How can 1% of something equal nothing?
When Is Packer Right?
Packer is another useful tool that Devops can use to automate. Like AWS own EC2 Image Builder, it allows you to create the images that you boot your instances off of. Think of them as docker images for the server itself.
For example, there are lots of dependencies your application requires, and you’ll install with your package manager. And there are services you want to start. You *could* use an ansible playbook to get these going, but better to build a new image that contains all the software you need on the box.
Packer easily sits into your CI pipeline, so you can have new software deployed and ready anytime.
The principal difference is that a new AMI requires you to spinup a new server. You can’t take action on a running server with this tool.
Related: Is Fred Wilson right about dealing in an honest, direct and transparent way?
When Does Ansible Make Sense?
In particular here’s what my response was about Ansible itself.
“Absolutely. It’s an interesting balance to strike.
Because of course packer or EC2 image builders are very powerful and fit neatly into a CI pipeline. That said there are things Ansible is nicely suited for too.
For example, I want to distribute public keys onto specific servers. I have a yml file with the keys. I have a new developer starting, I have him or her git checkout branch, edit keys.yml, commit, push changes, then make a pull request. When the new keys.yml file gets merged, an ansible playbook kicks off to distribute the new set of keys to the relevant servers.”
If you want to take actions on running servers, like deploying keys or other ongoing tweaks, that is where Ansible really shines.
Conclusion
When deciding between Ansible, Packer, and Terraform, it’s important to consider your specific needs. Terraform is great for creating infrastructure, while Packer is useful for building server images. Ansible is well-suited for tasks like distributing public keys to servers. Ultimately, the right tool depends on the job at hand. We hope you have found this guide helpful in choosing the right tool for you. Thanks for reading!