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.
Why
Interviewers ask this, and real teams use more than one tool. Knowing each tool's job avoids fights and duplicate work.
What
| 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
- Use Terraform (or similar) to create the VMs, networks and load balancers.
- Use Ansible to install and configure software on them.
- Keep shell scripts for tiny, local jobs.
- 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.
एका वाक्यात सांगा: Terraform घर बांधतो, Ansible घरात सामान लावतो.
एक लाइन में कहो: Terraform घर बनाता है, Ansible घर में सामान लगाता है.
Did you understand? Let us try it once more.