Ansible or Terraform?

Ansible or Terraform?

Selecting right tools and products is a prerequisite for any successful project and for DevOps, is no different. In this blog post, we compare two popular DevOps tools, Ansible and Terraform.
In DevOps model, there are no separate development and operations teams, but often merged and have a single team that takes care of entire life cycle of the project. The requirements of such teams and projects would typically be (i)Infrastructure and (ii)Servers with right versions, patches, and execution environment.
Both Ansible and Terraform are great in realizing infrastructure as code and helps in the repeatable creation of the environments. Which one is better?

Configuration management & Orchestration.

Configuration management tools focus on, well configuration. They help in automation of configuring systems, servers, deploy software, applying patches and other similar IT automation tasks.

In infrastructure orchestration tools, you describe the desired infrastructure as code (IAC), and the tool takes care of creating the environment, exactly as described. You can create identical environments any number of times using the same code. For example, you may have described in your IAC code that requires 5 EC2, 1 Load balancer, and 1 RDS database. Should you run into any production bugs, you can use the same IAC code to recreate an identical environment as live for debugging and fixing.

Differences

There is a considerable overlap in functionality provided by Ansible and Terraform (most of the DevOps tools, for that matter). Ansible excels as a configuration management tool whereas Terraform is great in describing and creating infrastructure written as code and is an orchestration tool.

With Terraform, we declare the desired state of the infrastructure and Terraform maintains what is available(based on its previous executions) and what needs to be created. This way, Terraform is stateful. Whereas Ansible does not keep track of previous executions and is stateless. Why this matter? If same Ansible Playbook is executed twice, you will end up with two sets of resources (e.g., EC2). The situation can become difficult in an auto-scaled environment, where you don’t know how many machines are currently in running state, and you will end up updating the Playbook to get a desired number of machines. With Terraform, you specify the desired count and Terraform takes care to bring the environment to the desired number of machines.

In our view, using Terraform for infrastructure management and Ansible for IT tasks would be a great combination for any IT project.

2018-05-01T04:41:44+00:00