News for hackers. Stuff that matters.
Re:Ask HN: What is the real difference between Terraform and... by styluss on Tuesday April 28, 2020 @07:03AM (#23005769)
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... by PaywallBuster on Tuesday April 28, 2020 @07:24AM (#23005896)
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... by 0xbadcafebee on Tuesday April 28, 2020 @08:06AM (#23006188)
Terraform is also mostly declarative.

You write the state you would like resources to be in. When you run terraform plan, it tells you how the state might end up. You run terraform apply and then get to find out what actually happens.

Will it create the resources how I expect? What will the resource's properties be? Will it fail half way into the changes and stop in a broken state? Will it blow away changes without asking/showing me first? Will it refuse to do anything? Who knows.

It's a guessing game. The only way to be sure of what it will or won't do is to write procedural code and tests, so at least you know what decisions it will and won't make.

'Declarative' is just us fooling ourselves that we can make complexity easy to deal with.

Re:Ask HN: What is the real difference between Terraform and... by piroux on Tuesday April 28, 2020 @07:56AM (#23006135)
To define something as declarative or imperative, it is important to compare the definition model to the execution model.

So I would rather say that Ansible is much less declarative than Terraform, because Ansible tasks (the different steps of an Ansible Playbook) are executed sequentially.

The tasks of Ansible are its statements, so yeah we would say that each Ansible task is declarative. And still, a requirement for that would be for the task to use a module/role which is idempotent, right? Another proof, Ansible natively offers loop, blocks, and conditional to control the execution flow throughout its tasks.

(This is not a critic of Ansible. I am happy to use it as is, as a high-level scripting mechanism.)

Re:Ask HN: What is the real difference between Terraform and... by bryogenic on Tuesday April 28, 2020 @07:52AM (#23006099)
There are so many answers here that are incorrect about what ansible is/does. Thank you for providing one that is correct.

If I could add to your answer:

Not only is ansible declarative and idempotent but it also includes countless cloud provisioning modules to bring idempotency to cloud environments.

Terraform may be easier for basic provisioning of cloud resources but I always switch back to ansible cloud modules when I need to do anything complex. Ansible also has the added benefit of easily context switching over to configuring the compute resources after they have launched.

Re:Ask HN: What is the real difference between Terraform and... by ntoshev on Tuesday April 28, 2020 @07:25AM (#23005902)
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... by ejanus on Tuesday April 28, 2020 @04:29PM (#23011551)
Thanks.