This content originally appeared on DEV Community and was authored by Bhaskar Sharma
Hello dev.to community!
Yesterday, I explored Terraform β automating cloud resources with Infrastructure as Code (IaC). Today, Iβm diving into Ansible, a tool that automates configuration management and application deployment.
Why Ansible Matters
Manually configuring servers (installing packages, updating configs) is repetitive and error-prone. Ansible makes it:
Agentless β Works over SSH, no extra software on servers.
Idempotent β Run the same playbook multiple times, results stay consistent.
Declarative β Define what you want, not how to do it.
Scalable β Manage 10 or 1,000 servers with the same playbook.
Core Ansible Concepts
Inventory β List of servers to manage.
Playbooks (YAML) β Define tasks like installing Nginx, updating configs, restarting services.
Modules β Pre-built actions (install packages, copy files, manage users, etc.).
Roles β Reusable, structured automation code.
Example: Install Nginx on a Server
Inventory (hosts):
[web]
192.168.1.10 ansible_user=ubuntu
Playbook (nginx.yml):
-
name: Install and Start Nginx
hosts: web
become: yes
tasks:- name: Install Nginx apt: name: nginx state: present update_cache: yes
- name: Start Nginx service: name: nginx state: started enabled: yes
Run:
ansible-playbook -i hosts nginx.yml
DevOps Use Cases
Configure CI/CD agents (install Docker, Git, Jenkins).
Manage application deployments (zero-downtime releases).
Ensure security compliance (patch updates across servers).
Combine with Terraform β Terraform provisions infra, Ansible configures it.
Pro Tips
Use Ansible Galaxy for pre-built roles.
Store playbooks in Git for version control.
Group variables in group_vars/ for cleaner management.
Use tags (–tags) to run specific tasks quickly.
Hands-on Mini-Lab (Try this!)
1⃣ Install Ansible on your local machine.
2⃣ Create an inventory file with one server.
3⃣ Write a playbook to install Nginx/Apache.
4⃣ Run ansible-playbook and verify.
Key Takeaway:
Ansible eliminates manual server setup by making configuration automated, repeatable, and scalable. A must-have skill for modern DevOps engineers!
Tomorrow (Day 13):
Iβll explore Jenkins β the powerhouse for CI/CD pipelines.
#Ansible #DevOps #Automation #IaC #ConfigurationManagement #SRE #CloudNative
This content originally appeared on DEV Community and was authored by Bhaskar Sharma