Ravindra BagaleCourses & study guides मराठी

Chapter 91: Ansible Deep Dive

DevOps

91.14 Comparison — Ansible vs shell scripts, Terraform and Puppet/Chef

Story (fictional teaching scenario). In a fictional architecture review in Hyderabad, Sophie from Montreal asked, "Do we need Ansible if we already have Terraform?" Meghna answered with one picture. Terraform creates the servers. Ansible configures what runs on them. Shell scripts are fine for tiny one-machine jobs. Puppet and Chef use agents that keep pulling config. Different jobs, sometimes used together.

Terraform creates infrastructure, Ansible configures it, shell is for tiny jobs, Puppet/Chef use pull agents.
Terraform creates infrastructure, Ansible configures it, shell is for tiny jobs, Puppet/Chef use pull agents.

Why

Interviewers ask this, and real teams use more than one tool. Knowing each tool's job avoids fights and duplicate work.

What

Comparison card: Ansible vs Terraform vs shell scripts vs Puppet and Chef
Comparison card: Ansible vs Terraform vs shell scripts vs Puppet and Chef
Topic Ansible Terraform Shell script Puppet / Chef
Main job Configure servers and apps Create cloud infrastructure Small one-machine tasks Keep server config in place
Agent on server No (SSH) Not applicable (cloud APIs) No Yes, usually
How it runs Push from control node Plan then apply Run by hand or cron Agent pulls on a timer
State Checks server each run Keeps a state file None Server checks in to master
Safe to rerun Yes, with good modules Yes, plan shows changes Only if you write it carefully Yes

How

  1. Use Terraform (or similar) to create the VMs, networks and load balancers.
  2. Use Ansible to install and configure software on them.
  3. Keep shell scripts for tiny, local jobs.
  4. Choose Puppet or Chef if you need agents that keep pulling config every few minutes.

Example 1: Same idea, three tools

Shell:      sudo apt-get install -y nginx
Ansible:    ansible.builtin.package: { name: nginx, state: present }
Terraform:  resource "aws_instance" "web" { ... }   (creates the server, not nginx)

What it means: Shell runs an install command. Ansible describes the state "nginx is present". Terraform makes the machine itself.

Example 2: Working together

1. terraform apply        -> 3 lab VMs created, IPs printed
2. IPs go into inventory  -> [web] section
3. ansible-playbook site.yml -> nginx + app config on all 3

What it means: Each tool does its own job in order. Chapter 79 has a dynamic inventory project that reads cloud servers automatically.

Ravindra Bagale's Tip

Say it in one line: Terraform builds the house, Ansible furnishes it.

Did you understand? Let us try it once more.