Live data from Hacker News

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

news.ycombinator.com

21–30 of 67 posts

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

#21
post #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 th…

Ansible has full integration with cloud providers API. It's actually better for managing instances and highly dynamic resources because it has much better state management than Terraform. If you (re)create some EC2 instances with Terraform. Terraform save the ID the first time they are created (in a state file that needs to be shared and keep in sync). It goes mental the next time it runs if any of the instances are…

How does the coverage of APIs compare. Just AWS is a gigantic set of APIs. I see most of what I'd need in the Ansible Module Index but it doesn't seem like it covers all that is available.

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

#22
post #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 th…

Ansible has full integration with cloud providers API. It's actually better for managing instances and highly dynamic resources because it has much better state management than Terraform. If you (re)create some EC2 instances with Terraform. Terraform save the ID the first time they are created (in a state file that needs to be shared and keep in sync). It goes mental the next time it runs if any of the instances are…

If you're using terraform with multiple people and are having problems keeping the state in sync I would suggest looking at remote terraform backends and state locking.

For example on AWS we use the s3 backend and a dynamodb table for locking. This way when terraform runs it will first acquire the lock, and then access the state on s3. And everyone is working on the same state.

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

#23
Terraform is a declarative way of setting up your cloud infrastructure. You specify the state you want your cloud to be in.

Ansible is an imperative way of setting up your cloud. You tell it to do certain things, install this package, copy this over there.

Hope it helps

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

#25
post #23

Terraform is a declarative way of setting up your cloud infrastructure. You specify the state you want your cloud to be in. Ansible is an imperative way of setting up your cloud. You tell it to do certain things, install this package, copy this over there. Hope it helps

Ansible is mostly declarative.

by default you use Ansible modules/roles and specify the desired state.

E.g. have these packages installed, have these directories created/deleted.

Use cases not covered by modules can fallback to using shell commands

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

#26
post #23

Terraform is a declarative way of setting up your cloud infrastructure. You specify the state you want your cloud to be in. Ansible is an imperative way of setting up your cloud. You tell it to do certain things, install this package, copy this over there. Hope it helps

Ansible is pretty declarative actually, it won't repeat tasks that are already performed if it can figure it out.

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

#27
If you are new to both and to IaC and DevOps as a whole:

Ansible is for 'inside' virtual machines or computers, Terraform is for 'outside' virtual machines or computers.

Inside a machine you might have software, configuration, assets. Outside a machine you might network connections, firewalls, disks, dns etc.

This isn't a comprehensive comparison, but when you start from nothing, it doesn't really help to do a syntax, provider or imperative vs. declarative.

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

#28
Ansible is primarily used for provisioning resources, on the other hand, Terraform is used for managing and deploying cloud resources. This differentiation falls fairly well in the concept of immutable infrastructure.

If you're familiar with Packer, then Packer is responsible for creating identical VM images which can be integrated to a CI pipeline and provisioned and baked using Ansible. This baked image is then deployed using Terraform.

Be advised that provisioning in Terraform during VM deployment is not recommended since it increases startup time of the machine. To perform ad hoc configuration management, you use Ansible.

You could very well use Ansible for managing and deploying cloud resources, but that's not what it's meant to do. Moreover, Ansible does not support the concept of state as does Terraform.

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

#29
post #21

Earlier quoted context omitted.

Ansible has full integration with cloud providers API. It's actually better for managing instances and highly dynamic resources because it has much better state management than Terraform. If you (re)create some EC2 instances with Terraform. Terraform save the ID the first time they are created (in a state file that needs to be shared and keep in sync). It goes mental the next time it runs if any of the instances are…

How does the coverage of APIs compare. Just AWS is a gigantic set of APIs. I see most of what I'd need in the Ansible Module Index but it doesn't seem like it covers all that is available.

Terraform has way more coverage. I used ansible for aws a couple years ago and needed to rewrite many of the modules myself.

Tracking AWS apis is a fulltime job and ansible for clouds just isn’t popular enough.

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

#30
post #16

There are five broad categories of IAC (Infrastructure as a Code) tools: a)Ad hoc scripts The most straightforward approach to automating anything is to write an ad hoc script. You take whatever task you were doing manually, break it down into discrete steps, use your favorite scripting language (e.g., Bash, Ruby, Python) to define each of those steps in code, and execute that script on your server b) Configuration m…

Thank you for this; it's the clearest explanation I've read.
Post reply on HN