Configuration Management with Ansible: A Practical Guide for DevOps

Sravya BollaSravya Bolla
2 min read

Managing infrastructure manually across multiple servers is time-consuming, error-prone, and inefficient. You’d be updating packages, patching systems, and configuring services — one server at a time. That’s where Configuration Management Tools come in, and Ansible shines among them for its simplicity and agentless architecture.

What is Configuration Management?

Configuration Management is the practice of:

  • Configuring servers automatically

  • Managing infrastructure state

  • Ensuring consistency across environments

Traditionally, sysadmins wrote bash scripts — but those often broke across distros. What worked on Ubuntu might fail on CentOS. Manual patching? A recipe for chaos.

Why Use Configuration Management Tools?

These tools let you:

  • Automate configurations

  • Maintain consistency

  • Scale easily

  • Eliminate human error

Popular tools:
✅ Ansible
✅ Puppet
✅ Chef
✅ SaltStack

But today, our focus is Ansible.

Project Goal

Automate the installation of NGINX on multiple Linux servers using Ansible.

But first… you must enable SSH passwordless authentication.

Step 1: Passwordless SSH Setup (Manual and Safe Way)

We don’t use ssh-copy-id here. Instead, we manually copy the public key:

✅ On the Control Node:

ssh-keygen

This generates:

  • ~/.ssh/id_rsa (private key)

  • ~/.ssh/id_rsa.pub (public key)

Never share your private key

✅ On Each Target Node:

  1. SSH into the target:
ssh key-pair user@192.168.1.10
  1. Open the authorized_keys file:
nano ~/.ssh/authorized_keys
  1. Paste the contents of the control node's id_rsa.pub here.

  2. Be careful not to delete existing lines!

Repeat this process for all target servers.

Project Structure

ansible-nginx-project/
├── inventory
└── nginx-playbook.yml

inventory – Your Inventory File

[webservers]
192.168.1.10
192.168.1.11

You can replace IPs with hostnames or use a dynamic inventory for cloud-based infrastructure.


nginx-playbook.yml – Your Ansible Playbook

---
- name: Install and Start NGINX on Web Servers
  hosts: webservers
  become: yes

  tasks:
    - name: Install NGINX
      apt:
        name: nginx
        state: present
        update_cache: yes

    - name: Ensure NGINX is running
      service:
        name: nginx
        state: started
        enabled: yes

Run the Playbook

ansible-playbook -i inventory nginx-playbook.yml

✅ Verify on the Target Nodes

SSH into any target server and run:

sudo systemctl status nginx

You should see:

Active: active (running)

That’s It!

You’ve just automated your first infrastructure task with Ansible — without touching a single target server’s shell after initial setup.

Whether you're a student, DevOps enthusiast, or engineer — this is your first step into the world of elegant and scalable automation.

Hope you like it:)

0
Subscribe to my newsletter

Read articles from Sravya Bolla directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sravya Bolla
Sravya Bolla