DevOps Day 13 — Getting Started with Ansible: Installation, Ad-hoc Commands & Playbooks
Welcome to Day 13 of the DevOps Series.
As infrastructure grows, managing servers manually becomes difficult and error-prone.
This is where Ansible plays a major role in DevOps by enabling automation, consistency, and scalability.
In Day 13, we focus on hands-on Ansible basics — from installation to running our first playbook.
✅ What We’ll Learn Today
-
How to install Ansible
-
Why passwordless SSH is required
-
Running Ansible ad-hoc commands
-
Creating inventory files
-
Writing and executing Ansible playbooks
-
Understanding verbose logs
-
Introduction to Ansible roles
πΉ 1. Ansible Installation
Ansible is usually installed on a control node (your laptop or EC2 instance).
On Ubuntu:
Other platforms:
-
Mac: Homebrew (
brew install ansible) -
Windows: Chocolatey (mainly for testing)
π Using package managers is recommended because they handle dependencies automatically.
Verify installation:
πΉ 2. Passwordless Authentication (Very Important)
Ansible works using SSH, so it must connect to target servers without asking for a password.
Step 1: Generate SSH key
Press Enter for all options.
Step 2: Copy public key to target server
After this, you should be able to login without a password:
✅ This is mandatory for Ansible automation.
πΉ 3. Ansible Inventory File
Inventory defines which servers Ansible manages.
Example:
You can group servers logically:
-
web servers
-
database servers
-
application servers
This makes targeting easy and clean.
πΉ 4. Ansible Ad-hoc Commands
Ad-hoc commands are used for one-time tasks
(no playbook required).
Example: ping all servers
Create a file on all servers:
π Useful for:
-
checking connectivity
-
restarting services
-
quick troubleshooting
πΉ 5. Writing Your First Ansible Playbook
Playbooks are written in YAML format.
Basic YAML structure:
Key sections:
-
name→ description -
hosts→ target machines -
become→ run as root -
tasks→ automation steps
π Always prefer Ansible modules over shell commands.
πΉ 6. Executing the Playbook
You’ll see:
-
Gathering facts
-
Task execution
-
Success or failure status
This ensures repeatable and reliable automation.
πΉ 7. Verbose Mode (Debugging)
To understand what Ansible is doing internally:
More v = more details.
Very useful during troubleshooting.
πΉ 8. Introduction to Ansible Roles
When playbooks become large, managing everything in one file becomes messy.
π Roles help organize code
Create a role:
Roles separate:
-
tasks
-
variables
-
handlers
-
templates
-
files
Used heavily in:
-
Kubernetes setup
-
Production automation
-
Enterprise environments
π Why This Matters in Real DevOps
Ansible helps DevOps engineers:
-
Automate server setup
-
Maintain consistency
-
Reduce manual errors
-
Manage thousands of servers
-
Work efficiently with cloud infrastructure
This is why Ansible is one of the most in-demand DevOps skills today.
Comments
Post a Comment