Live data from Hacker News

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

news.ycombinator.com

51–60 of 67 posts

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

#51

I like both of them. One thing interesting in Terraform is the ability to say I want to go from X to Y and see what will be the impact without actually doing the steps. Otherwise both are quite good.

Check mode in ansible

> --check

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

#52
There are a lot of answers but none are geared to the beginner. I read the question as asking for an answer like the below-

To a large degree expressing something is a "poor choice" is an opinion, maybe expert, about optimizations, not about capabilities.

When one is learning, adopting the value judgements of experts is a form of premature optimization that actually prevents learning.

The only way to build your own opinions is through your own experience. You will need to have your own problems, and solve them using a variety of tools, to build your own opinions.

Try both tools in real problems, and the mental model that accrues in your experience will start to guide your opinions about ways to optimize your work.

Also- everybody is just making it up. And all tools suck.

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

#53

Earlier quoted context omitted.

I'm not sure why you've had problems with Terraform trying to nuke things - I'd say the planning capability was one of its strong points. A quick glance at the plan will tell you what it needs to remove to put an environment in the expected state (and it's called out again in the destroy count summary at the end of then plan). Terraform doesn't "accidentally" delete things - it's doing it because you've told it they'…

>> Terraform doesn't "accidentally" delete things - it's doing it because you've told it they're not needed anymore. That's putting it backward to say the least. One never tells terraform that something is not needed anymore. One declares what is needed and terraform will find a way to get there by altering/creating/deleting stuff. There is a review phase of course and it's very important because it might do anything…

>> There is a review phase of course and it's very important because it might do anything. Anybody who's had to use terraform can attest that it is scary to run.

This is no worse than Ansible - if for a set of EC2 instances the user "set to 0 to delete them" then Ansible will blindly do as requested and be just as destructive. On the other hand:

* Terraform does its best to enforce the recommended plan/apply workflow - the plan is always presented before any changes are made, and auto-approval is strongly discouraged.

* There are multiple options for review - do it there and then, or store the plan as an artefact and share with others for review.

* It doesn't matter when you run a stored plan - the plan is the set of changes that will be applied regardless of current state.

* The summary makes very clear if anything is going to be destroyed in bright red text.

Ansible offers some visibility of what it will do with dry runs, although it's not as complete - there's no way to guarantee it will do the same thing next time if changes have been made in the interim.

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

#54

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…

Ansible also does 'outside' virtual machines. See https://docs.ansible.com/ansible/2.3/list_of_cloud_modules.h...

Yep it does indeed, Ansible also can talk to AWS, GCP etc, but that is not the point ;-) (And Terraform can SSH in to machines and execute commands just fine)

If someone is new to this, having a strong boundary makes it much easier to process how those systems are intended to be used and how they are built. There are certain assumptions made in both that make them work differently, i.e. being command centric vs. resource centric. That's interesting when someone is up to the point where you can apply what you know in a more general or generic sense, because then he systems themselves matter less.

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

#55
post #38

Earlier quoted context omitted.

Ansible doesn't handle the delete case. It has no way to "notice" that a resource is no longer in the playbook and therefore should be removed. This is why terraform keeps it's state file so it can do that sort of operation.

Ansible handles deletion just fine. Provisioning instances for example takes a number of instances, set to 0 to delete them. The more stable resources have a separate command to delete like ec2_vpc vs ec2_vpc_delete. IMO The way terraform automatically/accidentally delete stuff is a major design flaw, not a feature to emulate. It's madness that it tries to auto nuke potentially a whole company just because it lost tr…

    set to 0 to delete them
then I have a step in there that I will have to remove in a subsequent commit. The process as you describe it for a list of set of instances is:

1. commit a change that sets to 0

2. deploy change.

3. Make a new commit removing the step.

In Terraform it's just

1. Commit a change removing the resource.

2. Deploy

No cleanups that might be forgotten. No double commits for something that should just be 1.

Terraform doesn't "lose track" of an identifier. It's state file management is pretty robust and it has built in locking for the shared use case.

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

#56
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…

Thanks so much! The dots are getting connected.

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

#57
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

Thanks.

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

#58

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 i…

This is not a bad high level description. I asked myself almost the exact same question as the OP a year ago, though I had prior experience with Ansible, so knew what I was getting into. My advice to the OP, as it's all new to you, is to learn Ansible. It will require more work than Terraform, but Ansible can be made to perform the same functions as Terraform, and a heck of a lot more stuff that will prove useful to…

I learnt a bunch ...I will build up my knowledge from Ansible first.

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

#59

There are a lot of answers but none are geared to the beginner. I read the question as asking for an answer like the below- To a large degree expressing something is a "poor choice" is an opinion, maybe expert, about optimizations, not about capabilities. When one is learning, adopting the value judgements of experts is a form of premature optimization that actually prevents learning. The only way to build your own o…

Okay...and thanks for being frank

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

#60
post #20

Terraform tracks and provisions cloud provider state. Ansible you need to pass and parse Ansible output around which can take considerable time. Terraform tells how your Infastructure should look like. Ansible what software should be on your infrastructure/servers. I tend to use Terraform to describe how the underlying Cloud infrastructure should look like. I use Ansible to describe and configure what software should…

Terraform does software/config just fine. "Immutable infrastructure" and all
Post reply on HN