SlideShare a Scribd company logo
Terraform vs. Ansible: When to
Use Each
When looking for an infrastructure-as-code (IaC) tool, you’ll find several options, including Terraform and
Ansible. Both of these IaS tools provision infrastructure in the cloud, but they have distinct differences that
make one better to use than the other in certain environments, which make each tool more suitable than
the other for certain use cases. Terraform is more of a provisioning tool, while Ansible is used for
configuration of cloud infrastructure.
What Does Terraform Do?
Instead of manually configuring cloud infrastructure (e.g., virtual machines), Terraform lets DevOps teams
write configuration scripts—one or more text files written in Hashicorp Control Language—that deploy
resources remotely using automation. It can be used against any infrastructure for which a provider exists.
How Does Terraform Work?
Terraform uses a configuration as the reference for the desired state of infrastructure resources and
ensures that the provisioned resources match what is specified in the configuration. The use of its
configurations ensures that infrastructure is deployed in a consistent manner. It can deploy virtual
machines, network components like firewalls, database servers, and any other hardware used to run the
cloud environment.
What Does Ansible Do?
Ansible is used to configure infrastructure. After you deploy infrastructure, you might need to make
changes to configurations to support new software or upgraded features. DevOps can write automation
scripts to change configurations across multiple cloud resources.
How Does Ansible Work?
When you want to automatically configure infrastructure in the cloud, it would be better to use Ansible than
Terraform. Developers create YAML files to automate configuration deployments in the cloud. Terraform
also deploys configurations, but Ansible will let you update and change current infrastructure
configurations.
Ansible works with “playbooks,” which are procedural scripts that let developers define what they want to
execute on infrastructure. It works with DevOps operations to continually make changes to infrastructure
as developers deploy applications.
Terraform vs. Ansible: 3 Similarities
Although Terraform and Ansible are used for different purposes, they have some similarities. They both
have orchestration capabilities that let DevOps deploy infrastructure to the cloud. While infrastructure is
deployed, they both configure it at the same time to make it functional for developers or operations people.
They both work on virtual machines without installing agents on the remote infrastructure, and both work
with SSH connections. Neither of them require expensive third-party infrastructure to manage their state,
meaning that Ansible and Terraform are considered masterless systems.
Terraform vs. Ansible: 3 Differences
If you use both Terraform and Ansible in your environment, you should know that they have differences,
which define their uses in DevOps. Ansible is for configurations, while Terraform is for provisioning mutable
infrastructure. It uses the HLC syntax, while Ansible uses the common YAML syntax.
The big difference is that Terraform is declarative, which means that code can be dispersed across multiple
files, and code isn’t executed in sequence. The Ansible YAML syntax is procedural, which means that every
line of code is executed sequentially. Ansible playbooks are a series of executable tasks used to define
configurations, which usually needs to be done in order for it to be successful.
Terraform allows for mutable functionality, which means that infrastructure can be changed to run newer
applications or hardware. Ansible is immutable, which means that new infrastructure must be deployed if
you change configurations.
When to Use Terraform
If you have a DevOps team that needs to rapidly deploy infrastructure along with applications, Terraform
will give developers easy access to API endpoints for fast deployments. Developers can connect to a
terminal where they can write and test code before they put it into production.
It is mainly used for simple provisioning without many configurations. It has some configuration
functionality during deployment, but it’s not a good choice if you need to automate configurations on your
public cloud hardware. For example, provisioning a virtual machine for use with software could be a good
use for Terraform.
When to Use Ansible
After provisioning hardware, Ansible is a good choice for continual configuration of resources. Ansible is
specific for configurations, so it’s best for automating cloud resources to work with specific applications. It
can also be used to help other departments as they need to make configuration changes to infrastructure.
For example, let’s say that you provision a virtual machine but need to add it to a load balancer. The
configurations could be automated using Ansible.
Terraform vs. Ansible: FAQs
Can you run Ansible from Terraform?
Although Ansible and Terraform are different platforms, you can invoke Ansible from Terraform. This would
be done after you provision infrastructure from Terraform and then configure it using Ansible. You first
need to create an Ansible playbook and then call Ansible from your Terraform HCL script.
Can Ansible replace Terraform?
Ansible can be used to deploy some infrastructure, but it can’t completely replace Terraform. It deploys
infrastructure, and then Ansible will execute after infrastructure deployment to configure it. They work well
bundled together in a DevOps environment.

More Related Content

Similar to Terraform vs Ansible -1.pdf

Terraform
TerraformTerraform
Terraform
An Nguyen
 
Collaborative Terraform with Atlantis
Collaborative Terraform with AtlantisCollaborative Terraform with Atlantis
Collaborative Terraform with Atlantis
Ferenc Kovács
 
Infrastructure as Code.docx
Infrastructure as Code.docxInfrastructure as Code.docx
Infrastructure as Code.docx
MuhammadKhalil502533
 
KCD Italy 2022 - Application driven infrastructure with Crossplane
KCD Italy 2022 - Application driven infrastructure with CrossplaneKCD Italy 2022 - Application driven infrastructure with Crossplane
KCD Italy 2022 - Application driven infrastructure with Crossplane
sparkfabrik
 
Deploy resources on Azure using IaC (Azure Terraform)
Deploy  resources on Azure using IaC (Azure Terraform)Deploy  resources on Azure using IaC (Azure Terraform)
Deploy resources on Azure using IaC (Azure Terraform)
George Grammatikos
 
TNAPS 3 Architecture
TNAPS 3 ArchitectureTNAPS 3 Architecture
TNAPS 3 Architecture
tncor
 
Maximizing DevOps Efficiency with Terraform.pptx
Maximizing DevOps Efficiency with Terraform.pptxMaximizing DevOps Efficiency with Terraform.pptx
Maximizing DevOps Efficiency with Terraform.pptx
Catherine William
 
Aws migration strategy
Aws migration strategyAws migration strategy
Aws migration strategy
Suliman Lei
 
SynergyTop - Comparing Terraform Vs. Pulumi Which Infrastructure-As-Code (IaC...
SynergyTop - Comparing Terraform Vs. Pulumi Which Infrastructure-As-Code (IaC...SynergyTop - Comparing Terraform Vs. Pulumi Which Infrastructure-As-Code (IaC...
SynergyTop - Comparing Terraform Vs. Pulumi Which Infrastructure-As-Code (IaC...
SynergyTop Inc.
 
What is the Benefit of Using Terraform?
What is the Benefit of Using Terraform?What is the Benefit of Using Terraform?
What is the Benefit of Using Terraform?
Ravendra Singh
 
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
Alex Cachia
 
What are the Benefits of Using Terraform?
What are the Benefits of Using Terraform?What are the Benefits of Using Terraform?
What are the Benefits of Using Terraform?
Ravendra Singh
 
Roboconf Detailed Presentation
Roboconf Detailed PresentationRoboconf Detailed Presentation
Roboconf Detailed Presentation
Vincent Zurczak
 
Gluecon Preso: Hybrid Container Infrastructure
Gluecon Preso: Hybrid Container InfrastructureGluecon Preso: Hybrid Container Infrastructure
Gluecon Preso: Hybrid Container Infrastructure
rhirschfeld
 
Creating AWS infrastructure using Terraform
Creating AWS infrastructure using TerraformCreating AWS infrastructure using Terraform
Creating AWS infrastructure using Terraform
Knoldus Inc.
 
Kubernetes vs Terraform 111023.pdf
Kubernetes vs Terraform 111023.pdfKubernetes vs Terraform 111023.pdf
Kubernetes vs Terraform 111023.pdf
JacksonLane4
 
AWS Vs Firebase Vs Heroku- Which is Suitable for your Next Project?
AWS Vs Firebase Vs Heroku- Which is Suitable for your Next Project?AWS Vs Firebase Vs Heroku- Which is Suitable for your Next Project?
AWS Vs Firebase Vs Heroku- Which is Suitable for your Next Project?
Robert Anderson
 
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik
 
Unleashing the Power of Terraform and Azure DevOps
Unleashing the Power of Terraform and Azure DevOpsUnleashing the Power of Terraform and Azure DevOps
Unleashing the Power of Terraform and Azure DevOps
Catherine William
 
Effective terraform
Effective terraformEffective terraform
Effective terraform
Calvin French-Owen
 

Similar to Terraform vs Ansible -1.pdf (20)

Terraform
TerraformTerraform
Terraform
 
Collaborative Terraform with Atlantis
Collaborative Terraform with AtlantisCollaborative Terraform with Atlantis
Collaborative Terraform with Atlantis
 
Infrastructure as Code.docx
Infrastructure as Code.docxInfrastructure as Code.docx
Infrastructure as Code.docx
 
KCD Italy 2022 - Application driven infrastructure with Crossplane
KCD Italy 2022 - Application driven infrastructure with CrossplaneKCD Italy 2022 - Application driven infrastructure with Crossplane
KCD Italy 2022 - Application driven infrastructure with Crossplane
 
Deploy resources on Azure using IaC (Azure Terraform)
Deploy  resources on Azure using IaC (Azure Terraform)Deploy  resources on Azure using IaC (Azure Terraform)
Deploy resources on Azure using IaC (Azure Terraform)
 
TNAPS 3 Architecture
TNAPS 3 ArchitectureTNAPS 3 Architecture
TNAPS 3 Architecture
 
Maximizing DevOps Efficiency with Terraform.pptx
Maximizing DevOps Efficiency with Terraform.pptxMaximizing DevOps Efficiency with Terraform.pptx
Maximizing DevOps Efficiency with Terraform.pptx
 
Aws migration strategy
Aws migration strategyAws migration strategy
Aws migration strategy
 
SynergyTop - Comparing Terraform Vs. Pulumi Which Infrastructure-As-Code (IaC...
SynergyTop - Comparing Terraform Vs. Pulumi Which Infrastructure-As-Code (IaC...SynergyTop - Comparing Terraform Vs. Pulumi Which Infrastructure-As-Code (IaC...
SynergyTop - Comparing Terraform Vs. Pulumi Which Infrastructure-As-Code (IaC...
 
What is the Benefit of Using Terraform?
What is the Benefit of Using Terraform?What is the Benefit of Using Terraform?
What is the Benefit of Using Terraform?
 
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
 
What are the Benefits of Using Terraform?
What are the Benefits of Using Terraform?What are the Benefits of Using Terraform?
What are the Benefits of Using Terraform?
 
Roboconf Detailed Presentation
Roboconf Detailed PresentationRoboconf Detailed Presentation
Roboconf Detailed Presentation
 
Gluecon Preso: Hybrid Container Infrastructure
Gluecon Preso: Hybrid Container InfrastructureGluecon Preso: Hybrid Container Infrastructure
Gluecon Preso: Hybrid Container Infrastructure
 
Creating AWS infrastructure using Terraform
Creating AWS infrastructure using TerraformCreating AWS infrastructure using Terraform
Creating AWS infrastructure using Terraform
 
Kubernetes vs Terraform 111023.pdf
Kubernetes vs Terraform 111023.pdfKubernetes vs Terraform 111023.pdf
Kubernetes vs Terraform 111023.pdf
 
AWS Vs Firebase Vs Heroku- Which is Suitable for your Next Project?
AWS Vs Firebase Vs Heroku- Which is Suitable for your Next Project?AWS Vs Firebase Vs Heroku- Which is Suitable for your Next Project?
AWS Vs Firebase Vs Heroku- Which is Suitable for your Next Project?
 
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
 
Unleashing the Power of Terraform and Azure DevOps
Unleashing the Power of Terraform and Azure DevOpsUnleashing the Power of Terraform and Azure DevOps
Unleashing the Power of Terraform and Azure DevOps
 
Effective terraform
Effective terraformEffective terraform
Effective terraform
 

Recently uploaded

一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
ewymefz
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
FP Growth Algorithm and its Applications
FP Growth Algorithm and its ApplicationsFP Growth Algorithm and its Applications
FP Growth Algorithm and its Applications
MaleehaSheikh2
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
Jpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization SampleJpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization Sample
James Polillo
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
vcaxypu
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
ArpitMalhotra16
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
ocavb
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
benishzehra469
 
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
correoyaya
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
NABLAS株式会社
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
enxupq
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
Opendatabay
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
nscud
 

Recently uploaded (20)

一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
FP Growth Algorithm and its Applications
FP Growth Algorithm and its ApplicationsFP Growth Algorithm and its Applications
FP Growth Algorithm and its Applications
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
Jpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization SampleJpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization Sample
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
 
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 

Terraform vs Ansible -1.pdf

  • 1. Terraform vs. Ansible: When to Use Each When looking for an infrastructure-as-code (IaC) tool, you’ll find several options, including Terraform and Ansible. Both of these IaS tools provision infrastructure in the cloud, but they have distinct differences that make one better to use than the other in certain environments, which make each tool more suitable than the other for certain use cases. Terraform is more of a provisioning tool, while Ansible is used for configuration of cloud infrastructure. What Does Terraform Do? Instead of manually configuring cloud infrastructure (e.g., virtual machines), Terraform lets DevOps teams write configuration scripts—one or more text files written in Hashicorp Control Language—that deploy resources remotely using automation. It can be used against any infrastructure for which a provider exists. How Does Terraform Work? Terraform uses a configuration as the reference for the desired state of infrastructure resources and ensures that the provisioned resources match what is specified in the configuration. The use of its configurations ensures that infrastructure is deployed in a consistent manner. It can deploy virtual
  • 2. machines, network components like firewalls, database servers, and any other hardware used to run the cloud environment. What Does Ansible Do? Ansible is used to configure infrastructure. After you deploy infrastructure, you might need to make changes to configurations to support new software or upgraded features. DevOps can write automation scripts to change configurations across multiple cloud resources. How Does Ansible Work? When you want to automatically configure infrastructure in the cloud, it would be better to use Ansible than Terraform. Developers create YAML files to automate configuration deployments in the cloud. Terraform also deploys configurations, but Ansible will let you update and change current infrastructure configurations. Ansible works with “playbooks,” which are procedural scripts that let developers define what they want to execute on infrastructure. It works with DevOps operations to continually make changes to infrastructure as developers deploy applications. Terraform vs. Ansible: 3 Similarities Although Terraform and Ansible are used for different purposes, they have some similarities. They both have orchestration capabilities that let DevOps deploy infrastructure to the cloud. While infrastructure is deployed, they both configure it at the same time to make it functional for developers or operations people. They both work on virtual machines without installing agents on the remote infrastructure, and both work with SSH connections. Neither of them require expensive third-party infrastructure to manage their state, meaning that Ansible and Terraform are considered masterless systems. Terraform vs. Ansible: 3 Differences If you use both Terraform and Ansible in your environment, you should know that they have differences, which define their uses in DevOps. Ansible is for configurations, while Terraform is for provisioning mutable infrastructure. It uses the HLC syntax, while Ansible uses the common YAML syntax. The big difference is that Terraform is declarative, which means that code can be dispersed across multiple files, and code isn’t executed in sequence. The Ansible YAML syntax is procedural, which means that every line of code is executed sequentially. Ansible playbooks are a series of executable tasks used to define configurations, which usually needs to be done in order for it to be successful. Terraform allows for mutable functionality, which means that infrastructure can be changed to run newer applications or hardware. Ansible is immutable, which means that new infrastructure must be deployed if you change configurations. When to Use Terraform If you have a DevOps team that needs to rapidly deploy infrastructure along with applications, Terraform
  • 3. will give developers easy access to API endpoints for fast deployments. Developers can connect to a terminal where they can write and test code before they put it into production. It is mainly used for simple provisioning without many configurations. It has some configuration functionality during deployment, but it’s not a good choice if you need to automate configurations on your public cloud hardware. For example, provisioning a virtual machine for use with software could be a good use for Terraform. When to Use Ansible After provisioning hardware, Ansible is a good choice for continual configuration of resources. Ansible is specific for configurations, so it’s best for automating cloud resources to work with specific applications. It can also be used to help other departments as they need to make configuration changes to infrastructure. For example, let’s say that you provision a virtual machine but need to add it to a load balancer. The configurations could be automated using Ansible. Terraform vs. Ansible: FAQs Can you run Ansible from Terraform? Although Ansible and Terraform are different platforms, you can invoke Ansible from Terraform. This would be done after you provision infrastructure from Terraform and then configure it using Ansible. You first need to create an Ansible playbook and then call Ansible from your Terraform HCL script. Can Ansible replace Terraform? Ansible can be used to deploy some infrastructure, but it can’t completely replace Terraform. It deploys infrastructure, and then Ansible will execute after infrastructure deployment to configure it. They work well bundled together in a DevOps environment.