Unlocking Efficiency with Ansible: A Beginner's Journey.

Introduction

Ansible is an open-source IT configuration Management tool that automates and simplifies the management and configuration of a computer system, orchestrates complex deployment, and manages infrastructure as code.

Ansible is known for its simplicity, agentless architecture, and extensive support for a wide range of platforms and systems.

History

Micheal DeHaan developed Ansible in 2012 with the aim of providing a simple, agentless automation framework. In 2015 Red Hat acquired Ansible and then it has gained significant popularity and has become a widely adopted automation solution across the platform.

Before Ansible or any other tools like Puppet, chef, managing IT infrastructure and systems are often a manual and time-consuming Process. Administrators would manually log in to each system and make changes individually. Shell scripting is also used along with creating the Golden images.

About

Talking about Ansible it is written in Python language and has the simplest architecture among its completion which make it more powerful and easy to learn.

Ansible consists of two components :

  1. Ansible Control Node.

    The ansible control Node serves as the central management Point. It is where the system admin defines and executes the automation tasks. It contains the inventory where we list the address of the Node needed to be managed and the playbooks which define the desired state and action to be performed.

  2. Managed Nodes.

    These are the nodes or servers that Ansible manages and configures. Ansible communicates with these managed servers through ssh or another connection method without the need for any agents need to install on them.

Playbooks are written in YAML format. This makes Ansible easier to learn than other tools like Puppet, chef where we have to learn about the programming language.

Workflow

We define the inventory file that contains the list of the managed nodes which contain information like IP address, hostname. And then we create a playbook in YAML format which consists of a set of tasks specifying the action to be formed. And then we execute the ansible from the control node specifying the target hosts. It then connects to the managed nodes using ssh or other connection methods. It follows an idempotent execution model and provides real-time feedback.

Ansible's architecture and workflow provide a simple and agentless approach to automation.

Ansible Vs Chef

Ansible and Chef are both popular configuration management and automation tools, but they have different approaches and features.

  • The major difference is in the architecture. In Chef we have a chef workstation and chef server and nodes where the recipe is written in the ruby language and then wrap it with a cookbook and push it to the chef server using a knife. And the chef server connects with targeted nodes with bootstrapping.

  • Whereas we only have an ansible control node and we write our playbook in YAML and then we directly connect with worker nodes directly through the ssh connection or through other valid connection

2.

  • Chef uses a client-server architecture, where the Chef client needs to be installed on managed nodes, which communicate with the Chef Server.

  • Ansible follows an agentless architecture, meaning it doesn't require any software to be installed on the managed nodes.

3.

  • Ansible uses a push-based model, where the Control Node pushes configurations to the managed nodes. It applies changes to the managed nodes directly.

  • Chef uses a pull-based model, where the managed nodes periodically check the Chef Server for updates and configurations. The Chef client pulls the configurations and applies them to the managed nodes

These are some of the differences between the two configuration management and automation tools.

Example

Here in this example, we will look at how we create the control node and three nodes or server that is to be managed on AWS.

First, create one master node and three nodes EC2 Instance in AWS. You can click here for the guide. We can use the Ubuntu terminal from AWS itself.

$sudo apt update for updating to update the package lists for available software packages.

$sudo apt install ansible for installing Ansible.

The RSA Private key can be stored somewhere safe in local storage.

we can store that private key in the location /.ssh

We should create an inventory file whose default location is /etc/ansible/hosts.

but we can create the inventory file in any location.

The inventory file contains information such as IP addresses, hostnames, and groupings of the managed nodes.

we can check the inventory file using the below command.

$ansible-inventory --list -y -i <location-of-hosts>

We can use various modules in Ansible. Here for a short demonstration, we use the ping module.

$ansible all -m ping -i <location-of-inventory> --private-key= ~/.ssh/ansible_key

We will talk about different module types in upcoming blogs.

Advantage and Disadvantage

Advantage

  • Easy to learn and use as Ansible follows a simple YAML-based syntax that is easy to understand and write.

  • It is very consistent and lightweight and has no constraints regarding the underlying hardware.

  • It works on the PUSH mechanism.

Disadvantages

  • It may not be ideal for real-time interactive operations If we require immediate feedback or continuous communication with the managed hosts.

  • compared to agent-based tools, Ansible's agentless approach may introduce additional latency, as it relies on SSH connections for remote execution.

  • Lack of native Windows support, Although Ansible can manage Windows hosts, its Windows support is not as extensive as its support for Linux and other Unix-like systems

Conclusion

Ansible is a highly effective automation tool that revolutionizes IT infrastructure management. Its agentless architecture, intuitive syntax, and a vast collection of modules make it a popular choice for simplifying complex tasks. Ansible's versatility extends to various environments, including cloud platforms and network devices, enhancing its flexibility. Although it has minor limitations, such as the absence of a built-in reporting system and limited Windows support, these can be overcome with third-party integrations. Overall, Ansible empowers organizations with streamlined workflows, improved efficiency, and the ability to scale operations seamlessly, making it an invaluable asset in the era of automation.