In-Depth Analysis of Ansible’s Architecture and Workflow

Athira KK
6 min readOct 26, 2023

--

Hey Techies…👋

In this blog, we’re going to discuss about In-Depth Analysis of Ansible’s Architecture and Workflow.

🚀 Elevating Automation with Ansible Playbooks 🚀

Automation has emerged as the key to productivity and efficiency in the fast-paced field of information technology. Ansible Playbook, a potent technology that is transforming how we manage and orchestrate large systems, is also at the core of automation.

Ansible is an open-source automation tool known for its simplicity and lack of reliance on third-party solutions or complex security measures. It accomplishes end-to-end automation of various components through the use of playbooks. These playbooks are composed in a human-readable language, primarily YAML (Yet Another Markup Language), which is also used for most configuration files. This approach offers the notable advantage of accessibility, making it comprehensible even to newcomers in the IT field, while also facilitating debugging. In this article, we will delve deeper into the architecture of Ansible.

Ansible’s beauty lies in its versatility, designed to cater not just to single-tier deployments but also to complex multi-tier systems and infrastructures. It is frequently described as ‘agentless,’ indicating that it operates by establishing connections with nodes through default logins like SSH, simplifying the automation process.

The Ansible architecture serves as the foundation for the automation and orchestration capabilities that Ansible offers such as how Ansible’s components work together to streamline IT operations, improve efficiency, and reduce manual effort.

Here’s a more detailed overview of Ansible’s architecture:

🎯Users: Users who write Ansible playbooks directly interface with the Ansible automation engine, forming a direct connection to execute automation tasks.

🎯Ansible playbook: Playbooks are written in YAML and define a set of tasks to be executed on the managed nodes.

▪️Playbooks serve as the defining structure for your workflow, executing tasks in the exact order they are written. These playbooks are formatted in YAML, describing and executing tasks through Ansible. Additionally, you have the flexibility to launch tasks both synchronously and asynchronously using playbooks.

▪️In the architecture mentioned above, an array of host machines is connected to the Ansible server, with playbooks being pushed to these hosts through SSH. While SSH is a common connection method, Ansible provides various connection plugins for added versatility. For instance, the Docker container connection plugin allows seamless connection to Docker containers for immediate configuration.

▪️The core of Ansible’s automation lies in its Ansible automation engine. Users can directly execute playbooks that are deployed on the hosts. Within the Ansible automation engine, several components are at play, beginning with the host inventory — a comprehensive list of IP addresses of all the hosts.

Let’s now explore each component within the Ansible automation engine.

🎯Inventory: The inventory is a configuration file that contains a list of managed nodes. These nodes can be servers, network devices, or any system we want to automate.

▪️Ansible demonstrates its efficiency by simultaneously operating on multiple systems within your infrastructure. It achieves this by selecting specific segments of systems listed in Ansible’s inventory file, typically stored at the default location, /etc/ansible/hosts. If necessary, you can designate an alternative inventory file by using the -i <path> option in the command line. We will see this in a practical, hands-on lab.

🎯API : API facilitates in the creation of the required API for end-to-end module interaction.

▪️Ansible provides a range of APIs that allow external tools, applications, and systems to seamlessly integrate with Ansible. These APIs enable automation workflows to be triggered and managed from external platforms. It can be used to collect data and automate reporting processes. This is beneficial for monitoring and reporting on the state of managed systems and infrastructure.

▪️APIs facilitate the integration of Ansible with various external systems, including cloud platforms, configuration management databases (CMDBs), monitoring tools, and more. This integration ensures seamless communication and coordination between Ansible and other tools in the IT ecosystem.

🎯Modules : Ansible modules are small programs that execute specific tasks on managed nodes. They are responsible for carrying out the actual automation actions.

▪️Ansible modules are the building blocks of automation within the Ansible framework. These small, reusable units of code are designed to perform specific tasks, such as managing files, configuring services, or interacting with cloud providers.

▪️When multiple modules in Ansible share the same code, Ansible optimizes the process by consolidating these functions into module utilities. This practice reduces redundancy, streamlines maintenance, and enhances code consistency. As an example, the code responsible for parsing URLs is stored in ‘lib/ansible/module_utils/url.py’. Furthermore, Ansible allows you to create your own module utilities when needed. It’s worth noting that module utilities can be authored using either Python or PowerShell.

🎯Plugins: Plugins offer various options and extensions, enabling tasks like data transformation, log management, connection to inventory systems, and much more.

▪️Unlike modules that execute on the target system in separate processes (often remotely), plugins operate on the control node within the /usr/bin/ansible process.Plugins run on the target system, execute on the control node itself. This process simplifies the management of various tasks, enhancing overall efficiency.

▪️Ansible encourages users to develop their own plugins when the provided ones don’t meet unique requirements. Whether it’s creating custom inventory sources, modifying data, or implementing new output formats, you have the flexibility to craft plugins to suit your specific use cases.

🎯Public or Private cloud: They provide communication with all of the modules and APIs through this, with the entire cloud — demonstrating that security measures are in place.

🎯Networking: Networking employing an agentless approach to generate and manage valuable network configurations.

🎯Hosts : Hosts refers to the target machines, such as Linux or Unix systems, that are being automated and managed using Ansible.

🎯CMDB (Configuration Management Database): It is a kind of repository that consists of detailed information about the entire network of computers , configuration items, and their relationships.

How Ansible Works?

Ansible operates by connecting to the target nodes (Host1,Host2,Host3) and deploying lightweight programs known as “Ansible modules.” It connects to the target nodes, typically over SSH (though other connection methods can be configured). Once the SSH connection is established, Ansible executes the modules on the target nodes.After module execution, Ansible removes them, leaving the target systems in the desired state as defined in the playbook

Ansible is built upon three main components, each serving a distinct role in the automation process:

1. Control Machine:

  • The control machine acts as the orchestrator, managing the execution of Ansible playbooks.
  • It can be installed on your local machine or on any accessible system on the internet.
  • The control machine hosts the Ansible framework and playbooks, which define the desired state of the target systems.

2. Inventory:

  • The inventory is a critical component that provides a comprehensive list of all target machines (hosts) on which Ansible will operate.
  • It is essentially a catalog of the systems you intend to manage, specifying their IP addresses, domain names, and groupings.
  • Ansible connects to the target machines via SSH, performs various tasks, and installs necessary software as defined in the playbooks.

3. Playbook:

  • Playbooks serve as the heart of Ansible automation, containing a series of steps and tasks that instruct the control machine on what actions to take.
  • These actions include configuring software, deploying applications, and managing system settings.
  • Playbooks are written in YAML format and are responsible for defining the tasks that will be executed on the servers listed in the inventory file.

In simple terms, Ansible interacts with all the servers defined in the inventory through the SSH protocol which is a secure method of remote login. Every operation is done and file transfer is encrypted.

Ansible’s agentless approach eliminates the need to install and manage agents on target nodes.This simplicity streamlines the automation process and minimizes administrative overhead.

Alright, everyone, it’s time to roll up our theories. Starting from the next day, we’ll dive into hands-on labs and explore how to set up our learning environment for mastering Ansible expertise.

💹Next day — Setting up Lab environment for Ansible SkillBuilder Series.

⭐⭐⭐ Enjoy your learning….!!! ⭐⭐⭐

--

--

Athira KK
Athira KK

Written by Athira KK

AWS DevOps Engineer | Calico Big Cats Ambassador | WomenTech Global Ambassador | LinkedIn Top Cloud Computing Voice

No responses yet