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)