DEV Community

Bhaskar Sharma
Bhaskar Sharma

Posted on

πŸš€ Day 12 of My DevOps Journey: Ansible β€” Configuration Management Made Simple βš™οΈ

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

Top comments (0)