Say you have ten Linux servers and each one needs Nginx installed, a config file updated and a new user added. You could SSH into each one and type the same commands ten times, or write a shell script and hope it behaves the same everywhere. Ansible is the tool most teams pick instead: you describe the end state once, and it makes every server match.
The short answer: Ansible is an agentless configuration management tool. It connects to servers over SSH and runs tasks written in YAML playbooks, such as installing packages, copying files and restarting services. Learn it after you are comfortable with Linux and SSH, and alongside or just after Terraform. Most beginners can write a useful playbook within a few days.
Ansible sits next to Terraform in month three of our DevOps roadmap for freshers, the same order we follow in our DevOps training in Pune. This guide gets you to your first working playbook.
Why Ansible is popular
Three things make Ansible easy to adopt. It is agentless: nothing needs installing on the servers you manage, only SSH access and Python, which most Linux machines already have. Playbooks are plain YAML, so a colleague who has never used Ansible can usually read one and tell what it does. And tasks are idempotent: running the same playbook twice does not install Nginx twice. Ansible checks the current state and changes only what is different.
That last point is the real difference from a shell script. A script runs commands. A playbook describes a result, and Ansible works out what to do to reach it.
The building blocks
Inventory
The inventory lists the machines Ansible manages, grouped by role. A simple one is a text file:
[web]
10.0.1.10
10.0.1.11
[db]
10.0.2.20
Modules
Modules do the actual work. apt and dnf install packages, copy and template place files, service starts and stops services, and user manages accounts. There are thousands more, for cloud platforms, databases and network devices.
Playbooks and tasks
A playbook maps a group of hosts to a list of tasks. Each task calls one module with some settings.
Roles
Once playbooks grow, you split them into roles: a reusable folder of tasks, templates and variables for one job, such as setting up Nginx. Roles keep large projects tidy, and you can pull community roles from Ansible Galaxy.
Your first playbook
Start by checking that Ansible can reach your servers. This ad-hoc command pings every host in the inventory:
ansible all -i inventory.ini -m ping
Then save this as web.yml. It installs Nginx on Ubuntu servers, places a home page and makes sure the service is running:
- name: Set up web servers
hosts: web
become: true
tasks:
- name: Install nginx
apt:
name: nginx
state: present
update_cache: true
- name: Add home page
copy:
content: "Hello from {{ inventory_hostname }}"
dest: /var/www/html/index.html
- name: Make sure nginx is running
service:
name: nginx
state: started
enabled: true
ansible-playbook -i inventory.ini web.yml
Run it once and you will see tasks reported as changed. Run it again and they show ok, because the servers already match. If you edit the page content and run it a third time, only that one task changes. Watching this happen is the quickest way to understand idempotency.
Ansible and Terraform together
People often ask which one to learn. The honest answer is both, because they do different jobs. Terraform creates infrastructure: the VPC, the servers, the load balancer. Ansible configures what runs on those servers. A common pattern is Terraform building three EC2 instances and writing their IPs to an inventory, then Ansible installing and configuring the application on them.
If Terraform is new to you, our Terraform for beginners guide covers the infrastructure side with an AWS example.
Mistakes beginners make
- Using
shellorcommandfor everything. These modules run raw commands and lose idempotency. Use a proper module whenever one exists. - Putting passwords in playbooks. Use Ansible Vault to encrypt secrets before committing anything to Git.
- Ignoring YAML indentation. Most early errors are spaces in the wrong place. Use an editor with YAML support and run
ansible-playbook --syntax-check. - Skipping dry runs.
--check --diffshows what would change without changing it. Use it before touching shared servers. - Restarting services on every run. Use handlers, so a service restarts only when its config file actually changed.
A one-week practice plan
- Day 1: launch two small Linux VMs, set up SSH keys, write an inventory and get
ansible all -m pingworking. - Days 2 and 3: write the Nginx playbook above, then add a user, a firewall rule and a template with variables.
- Days 4 and 5: add a handler, encrypt a secret with Vault and convert the playbook into a role.
- Days 6 and 7: combine it with Terraform: create servers with code, then configure them with your role. Push the whole thing to GitHub with a README.
Ansible makes far more sense if your Linux basics are solid, so revisit Linux for DevOps if SSH, permissions or services still feel shaky. The finished Terraform and Ansible setup also makes a good portfolio piece; see our DevOps projects for your resume for how to present it.
Frequently asked questions
Is Ansible still worth learning with Kubernetes around?
Yes. Kubernetes manages containers, but someone still has to configure the servers, databases, network devices and legacy apps that do not run in containers. Many companies in Pune run a mix of both.
Do I need Python to use Ansible?
Ansible needs Python on the machines involved, but you do not need to write Python. Playbooks are YAML. Python only becomes useful if you later write custom modules.
Ansible or Chef or Puppet?
For a beginner, Ansible. It is agentless, quicker to set up and more common in current job listings. Chef and Puppet still run in some older enterprise setups, and the ideas transfer if you meet them later.
Can Ansible manage Windows servers?
Yes, over WinRM or SSH, using Windows-specific modules. Most learning material and most jobs focus on Linux, so start there.





