Ansible - What and Why? and How?

Bharadwaj ReddyBharadwaj Reddy
4 min read

It all started with IT organizations growing their infrastructures, managing them and maintaining them is a huge challenge, Especially if the organization runs on hundreds or thousands of servers. We must need the right tools that make the work simple.

Problems that Organizations Face:

  1. Manual Configuration Management: Configuring servers manually is time-consuming and prone to errors as server numbers grow. 📈

  2. Inconsistent Environments: Different configurations across development, testing, and production environments cause issues during deployments.

  3. Complexity of Multiple Tools: Managing several tools for configuration, deployment, and infrastructure adds complexity and inefficiencies.

  4. Security Concerns: Manually securing servers and applying patches often leads to missed updates and vulnerabilities.

Before tools like Ansible, organizations used configuration management tools such as Puppet, Chef, or Salt Stack. While these tools helped automate tasks, they had their own drawbacks.


Now, What is ansible?

Ansible is an open source automation tool that is used to simplify tasks like configuration management, application deployment, and infrastructure provisioning. It automates repetitive tasks in an organization.

  • Ansible is primarily built on Python and uses SSH (for Linux) and winRM (for Windows) to connect to systems.

  • Ansible automates a wide range of tasks, including configuring servers, deploying applications.


Ansible is famous for it’s agentless architecture i.e. we don’t need any agents on the target server to manage anything it uses SSH(Linux) and winRM(for windows) to communicate with the machines. Unlike Puppet or Chef, ansible is easy to setup and use.

It doesn’t leave any software on the servers, ansible sends python scripts to the target machine, which run the task and clean up themselves.

Ansible allows us to write playbooks, which are basically scripts in yaml

These playbooks consist of tasks which are to be performed on the target server

Ansible is promoted in organizations because of these key features

  • Automation of Repetitive Tasks: Ansible automates tasks like server setup, patching, and application deployment, it reduces manual work.

  • Consistent Configurations: Playbooks ensure that all environments are configured the same, reduces errors during deployments.

  • Simplified Tool Management: Ansible handles various tasks with one tool, minimizes the need for multiple tools and keeps it simple.


How Ansible does these things?

Ansible Playbooks, Inventory

Ansible Playbooks

An Ansible playbook is a file written in YAML that tells about the tasks you want to perform on your systems. Each playbook contains one or more plays, and each play defines a series of tasks that are executed on a single server or a group of servers.

Here’s a simple example of a playbook:

---
- name: Install Apache Web Server
  hosts: webservers 
  become: yes
  tasks:
    - name: Install Apache
      apt:
        name: apache2
        state: present

This playbook installs the Apache web server on all servers defined in the webservers group, ensuring that the package is installed and up-to-date.

Above you saw something called a group, this This group refers to the set of servers that are used as your web servers, we group them in inventory.

For more information on Playbooks refer this https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_intro.html

Ansible Inventory

An Ansible inventory is a file where you define the hosts or servers that Ansible will manage. The inventory can be as simple as a list of server IPs, or it can be organized into groups. For example, you might have a group of web servers, a group of database servers, and a group of application servers.

Here’s a simple example of an inventory file:

[webservers]
192.168.1.10
192.168.1.11

[dbservers]
192.168.1.12

This inventory groups servers into webservers and dbservers. When running a playbook, Ansible will target the appropriate group based on the tasks you define.

For reference, visit https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html

Installation:

Step -1 : Install ansible

We can install ansible using python

pip install ansible

on Linux machines

sudo apt install ansible

Conclusion

Ansible has become a key tool for organizations looking to automate and simplify their IT processes. By offering an agentless, easy-to-use platform, Ansible addresses many of the challenges organizations face—whether it’s manual configuration management, inconsistent environments, or security concerns. With its intuitive playbooks, flexible inventory management.

it’s a great tool for automation at scale

Thanks for reading 😊✌️

0
Subscribe to my newsletter

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

Written by

Bharadwaj Reddy
Bharadwaj Reddy

Hey there! I’m Bharadwaj Reddy, currently an undergrad at Keshav Memorial Institute of Technology. I’m a full stack developer who loves building cool web applications with React, Node.js, and MongoDB. On top of that, I also love exploring machine learning with TensorFlow and PyTorch. I’m pretty comfortable navigating GitHub for version control and love tinkering with AWS for deploying projects. I post my regular learnings on Devops and other studies