Ansible
Ansible has emerged as one of the most popular automation tools,
revolutionizing how organizations manage and deploy their IT infrastructure.
With its simple yet robust architecture, Ansible has gained widespread adoption
across diverse industries. In this blog post, we will delve into the
intricacies of Ansible architecture, exploring how it works and its key
components.
At its core, Ansible follows a client-server architecture model.
It has three main components: control nodes, managed nodes, and communication
channels.
Let's examine each of these components.
1. Control Node:
The control node acts as the central management point in Ansible
architecture. It is the machine from which Ansible is installed and executed.
The control node stores the inventory, playbooks, and modules to manage the
managed nodes. Ansible uses a declarative language called YAML to define
playbook tasks and configurations.
2. Managed Nodes:
Managed nodes are the machines that Ansible drives. They can be
physical servers, virtual machines, or even network devices. Ansible connects
to managed nodes over SSH or WinRM protocols, enabling seamless management
across different operating systems.
3. Communication Channels:
Ansible utilizes SSH or WinRM protocols to establish secure
communication channels between the control node and managed nodes. SSH is used
for Linux-based systems, whereas WinRM is for Windows-based systems. This
allows Ansible to execute commands, transfer files, and collect information
from managed nodes.
Playbooks and Inventory
As a best practice, you don't want your Ansible
architecture, which consists of playbooks and Inventory, to be too specific.
However, you need to have a certain level of abstraction and keep out precise
information. Therefore, to develop flexible code, you must separate
site-specific information from the code, which is done with variables in
Ansible.
Remember that when you develop dynamic code along with your
static information, you can use this on any site with minor modifications to
the variables themselves. However, you can have variables in different
places, and where you place variables, such as a play header or Inventory, will
take different precedence. So, variables can be used in your Ansible
deployment architecture to provide site-specific code.
Before you proceed, you may find the following posts helpful for
pre-information:
Network Configuration Automation
Ansible Variables
Network Traffic Engineering
Several megatrends have driven the move to an
Ansible architecture. Firstly, the rise of distributed computing made
the manual approach to almost anything in the IT environment obsolete. This was
not only because it caused many errors and mistakes but also because the
configuration drift from the desired to the actual
state was considerable.
This is not only an operational burden but also a considerable
security risk. Today, deploying applications by combining multiple
services that run on a distributed set of resources is expected. As a result,
configuration and maintenance are more complex than in the past.
You have two options to implement all of this. First, you can
connect these services by manually spinning up the servers, installing the
necessary packages, and SSHing to each one, or you
can go down the path of automation, in particular, automation with Ansible.
So, with Ansible deployment architecture, we have the Automation
Engine, the CLI, and Ansible Tower, which is more
of an automation platform for enterprise-grade automation. This post focuses on
Ansible Engine.
As a quick note, if you have environments with more than a few
teams automating, I recommend Ansible Tower or the open-source version of AWX.
Ansible Tower has a 60-day trial license, while AWX is fully open-sourced and
does not require a license. The open-source version of AWX could be a valuable
tool for your open
networking journey.
A Key Point: Risky: The Manual Way.
Let me put it this way: If you configure manually, you will
likely maintain all the settings. What about mitigating vulnerabilities and
determining what patches or packages are installed in a large environment?
How can you ensure all your servers are patched and secured
manually? Manipulating configuration files by hand is tedious,
error-prone, and time-consuming. Equally, performing pattern matching to make
changes to existing files is risky.
A Key Point: The issue of Configuration Drift
The manual approach will result in configuration drift, where
some servers will drift from the desired state. Configuration drift is caused
by inconsistent configuration items across devices, usually due to manual
changes and updates and not following the automation path. Ansible is all about
maintaining the desired state and eliminating configuration drift.
Ansible Workflow:
Ansible operates on a push-based model, where the control node
pushes configurations and commands to the managed
nodes. The workflow involves the following steps:
1. Inventory:
The inventory is a file that contains a list of managed nodes.
It provides Ansible with information such as IP addresses, hostnames, and
connection details to establish communication.
2. Playbooks:
Playbooks are YAML files that define the desired state of the
managed nodes. They consist of a series of tasks or plays, each representing a
specific action to be executed on the managed nodes. Playbooks can be as simple
as a single task or as complex as a multi-step deployment process.
3. Execution:
Ansible executes playbooks on the control node and communicates
with managed nodes to perform the defined tasks. It uses modules, which are
small programs written in Python or other scripting languages, to interact with
the managed nodes and carry out the required operations.
4. Reporting:
Ansible provides detailed reports on task execution status,
allowing administrators to monitor and troubleshoot any issues. This helps
maintain visibility and consistently apply the desired configurations across
the infrastructure.
Advantages of Ansible Architecture:
The Ansible architecture offers several advantages, making it a
preferred choice for automation:
1. Simplicity:
Ansible's architecture is designed to be simple and easy to
understand. Using YAML playbooks and declarative language allows administrators
to define configurations and tasks in a human-readable format.
2. Agentless:
Unlike traditional configuration management tools, Ansible
requires no agent software installed on managed nodes. This reduces complexity
and eliminates the need for additional overhead.
3. Scalability:
Ansible's highly scalable architecture enables administrators to
manage thousands of nodes simultaneously. SSH and WinRM protocols allow for
efficient communication and coordination across large infrastructures.
Components of Ansible Deployment Architecture
Configuration management
The Ansible architecture is based on a configuration
management tool that can help alleviate these challenges. Ansible replaces
the need for an operator to tune configuration files manually and does an
excellent job in application deployment and orchestrating multi-deployment
scenarios. It can also be integrated into CI/CD pipelines.
In reality, Ansible is
relatively easy to install and operate. However, it is not a single entity.
Instead, it comprises tools, modules, and software-defined infrastructure that
form the ansible toolset configured from a single host that can manage multiple
hosts.
We will discuss the value of idempotency with Ansible modules
later. Even with modules idempotency, you can still have users of Ansible
automate over each other. Ansible Tower or AWS is the recommended solution for
multi-team automation efforts.
Pre-deployed infrastructure: Terraform
Ansible does not deploy the infrastructure; you
could use other solutions like Terraform that are best suited for this.
Terraform is infrastructure as a code tool. Ansible Engine is more of a
configuration as code. The physical or virtual infrastructure needs to be there
for Ansible to automate, compared to Terraform, which does all of this for you.
Ansible is an easy-to-use DevOps tool that
manages configuration as code has in the same design through any sized
environment. Therefore, the size of the domain is irrelevant to Ansible.
As Ansible Connectivity uses SSH that runs over
TCP, there are multiple optimizations you can use to increase performance and
optimize connectivity, which we will discuss shortly. Ansible is often
described as a configuration management tool and is typically mentioned along
the same lines as Puppet, Chef, and Salt. However, there is a considerable
difference in how they operate. Most notably, the installation of agents.
Ansible architecture: Agentless
The Ansible architecture is agentless and
requires nothing to be installed on the managed systems. It is also serverless
and agentless, so it has a minimal footprint. Some configuration
management systems, such as Chef and Puppet, are pull-based by default.
Where agents are installed, periodically check
in with the central service and pull-down configuration. Ansible is
agentless and does not require the installation of an agent on the target to
communicate with the target host.
However, it requires connectivity from the
control host to the target inventory ( which contains a list of hosts that
Ansible manages) with a trusted relationship. For convenience, we can have
password less sudo connectivity between our hosts. This allows you to log in
without a password and can be a security risk if someone gets to your machines;
they could have escalated privileges on all the Ansible-managed hosts.