Live data from Hacker News

Ask HN: What is the real difference between Terraform and Ansible?

news.ycombinator.com

1–10 of 67 posts

Ask HN: What is the real difference between Terraform and Ansible?

#1
I am beginning to learn these tools and I noticed that Ansible is used to configure servers and Terraform does something similar but I can't figure what makes Ansible poor choice when doing provisioning? NB: I am still learning please bear with my poor use of technical terms.

Re: Ask HN: What is the real difference between Terraform and Ansible?

#2
Ansible connects to remote servers to configure them, while Terraform calls cloud provider API’s to provision resources.

For example, you can use Terraform to provision virtual machines, database instances, or Kubernetes clusters on AWS. Terraform does this via the AWS API.

In my opinion, Terraform is better for provisioning because of the way it manages its own state. Terraform remembers what resources it created the last time it ran, and can edit or delete them according to any change in your Terraform code.

I like Ansible, but not for managing cloud resources. Ansible has no memory. For example, if I ran a playbook that installs MySQL, Ansible has no built-in way to undo this change and bring me back to my previous state.

Re: Ask HN: What is the real difference between Terraform and Ansible?

#3
You can use Ansible to provision servers, it works, but if you do that a lot it's better to use Terraform. With Ansible you are a bit at a lower level and you need to manage the state of your system yourself. It's fine for 4 permanent VMs but not for more complicated infrastructures.

Re: Ask HN: What is the real difference between Terraform and Ansible?

#5
Terraform is very good when it comes to declaring topologies: “there should be N items of this type, in this network, with these characteristics”. It remembers state; as you add or remove stuff to your topology, it will take care of doing all the necessary work to go from topology A to topology B, and detect any inconsistency.

I don’t know Ansible much, but I believe it’s more of a procedure-oriented system, where you declare the steps necessary to reach A, then again to go from A to B. This can be an issue if any item is actually not in the state you expected.

Re: Ask HN: What is the real difference between Terraform and Ansible?

#9
Ansible is really SSH on steroid across multiple hosts, with extra commands that bash never added. It can configure servers and services. It can also configure cloud products and it's a better choice than Terraform for many things because it's more flexible.

Terraform can only provision cloud resources on AWS/GCP/Azure/other. Usually it gets support first for new products they release. Terraform is very static (see issues with sharing the state file) so it's more indicated to configure very static stuff, like networking and subnets.

Re: Ask HN: What is the real difference between Terraform and Ansible?

#10

You can use Ansible to provision servers, it works, but if you do that a lot it's better to use Terraform. With Ansible you are a bit at a lower level and you need to manage the state of your system yourself. It's fine for 4 permanent VMs but not for more complicated infrastructures.

I'm not very familiar with Ansible but consider it to be somewhat interchangeable with Puppet (which I use extensively at work). You can certainly use Puppet to manage thousands of hosts but it entirely depends on other practices and technologies (an external node classifier in Puppet's case) to keep things manageable. I assume the same is true for Ansible.
Post reply on HN