DEV Community

Dawood
Dawood

Posted on

Terraform vs Ansible: What I Learned as a DevOps Fresher

Terraform vs Ansible: What I Learned as a DevOps Fresher

Introduction

As part of my DevOps learning journey, I recently explored two important automation tools: Terraform and Ansible. At first, I was confused because both tools are used in automation, but after learning and practicing, I understood that they solve different problems.

In this blog, I’ll share what I learned about Terraform vs Ansible, their differences, and when to use each one.


What is Terraform?

Terraform is an Infrastructure as Code (IaC) tool developed by HashiCorp.

It helps us create and manage cloud infrastructure using code instead of manually creating resources in cloud platforms like AWS, Azure, or GCP.

Using Terraform, we can create:

  • EC2 Instances
  • IAM Users
  • S3 Buckets
  • VPCs
  • RDS Databases

Terraform uses configuration files written in HCL (HashiCorp Configuration Language).

Example Terraform workflow:

terraform init
terraform plan
terraform apply
Enter fullscreen mode Exit fullscreen mode

Caption:
Terraform provisioning AWS infrastructure


What is Ansible?

Ansible is an automation and configuration management tool.

It helps configure servers, install software, automate tasks, and manage application deployments.

For example, Ansible can:

  • Install Nginx or Apache
  • Configure Linux servers
  • Deploy applications
  • Automate repetitive tasks
  • Manage multiple servers

Ansible uses YAML playbooks for automation.

Example command:

ansible-playbook playbook.yml
Enter fullscreen mode Exit fullscreen mode

Caption:
Ansible automating server configuration


Terraform vs Ansible

Terraform Ansible
Infrastructure provisioning Configuration management
Creates cloud resources Configures servers
Uses HCL language Uses YAML
Agentless Agentless
Best for cloud infrastructure Best for automation & configuration

Real Example

If I want to create an EC2 instance in AWS, I can use Terraform.

Once the EC2 instance is created, I can use Ansible to:

  • Install software
  • Configure the server
  • Deploy applications

This means both tools can work together.

Terraform creates infrastructure → Ansible configures it

Caption:
Terraform and Ansible working together in DevOps


Key Differences I Learned

Terraform

✅ Best for cloud resource provisioning
✅ Works well with AWS, Azure, and GCP
✅ Uses Infrastructure as Code (IaC)

Ansible

✅ Best for server configuration
✅ Easy automation using YAML
✅ Useful for deployment and administration


Challenges I Faced

While learning both tools, I faced a few challenges:

  • Understanding the difference between provisioning and configuration
  • Terraform syntax errors
  • YAML indentation mistakes in Ansible
  • AWS permission-related issues

After practicing hands-on, the concepts became much clearer.


My Learning

After learning both tools, I understood:

Terraform is used to create infrastructure, while Ansible is used to configure infrastructure.

Both tools are important in DevOps and often work together in real projects.


Conclusion

Learning Terraform and Ansible helped me better understand DevOps automation. Instead of manually creating and configuring infrastructure, these tools help automate everything efficiently.

I’m continuing to explore more DevOps tools through hands-on learning and projects.

Thank you for reading!

Top comments (0)