Skip to main content

Understanding the basics of Ansible architecture

Introduction

Ansible is a powerful open-source automation tool developed by Michael DeHaan and released in 2012. The key aspect of Ansible is that it uses a no-agent, no-daemon, and serverless architecture for managing, configuring, and deploying software applications.

Ansible Architecture

Ansible's architecture is straightforward yet robust, consisting of several components which together provide a powerful and flexible automation solution.

1. Modules

Ansible Modules, also known as task plugins or library plugins, are standalone scripts that Ansible runs on your behalf. They are like the tools in your toolbox. There are hundreds of built-in modules available within Ansible, or you can even write your own.

ansible localhost -m ping

In this example, ping is a module that simply checks if we can connect to our hosts.

2. Inventory

The Inventory is a list of nodes or hosts with their IP addresses, databases, servers, etc. where you want your Ansible modules to run. This list can be as simple as a plain text file with a list of hostnames or IP addresses.

[webservers]
server1.example.com
server2.example.com

In this example, we have an inventory group called webservers with two servers.

3. Playbooks

Playbooks are the heart of Ansible and are written in YAML format. They describe the tasks to be performed by Ansible. Playbooks contain the steps which the user wants to execute on a particular machine. Playbooks are run sequentially.

---
- hosts: webservers
tasks:
- name: Ensure Apache is installed
yum:
name: httpd
state: present

This Playbook ensures that Apache (httpd) is installed on all web servers.

4. Configuration Files

Ansible uses an INI-style file for configuration. The default location for the file is /etc/ansible/ansible.cfg but you can create your own configuration file.

[defaults]
inventory=/etc/ansible/hosts
remote_user=ansible

Here, the configuration file specifies the inventory file location and the default user to log in as.

5. Plugins

Plugins are pieces of code that augment Ansible's core functionality. Ansible comes with a number of handy plugins, and you can easily write your own.

6. APIs

Ansible can connect with various cloud platforms and configure the systems through APIs. This includes platforms like AWS, Microsoft Azure, and Google Cloud.

Summary

Ansible's architecture is designed to be minimal, consistent, secure and highly reliable. With its modular design, it can adapt to many different environments and workflows. Now that we have covered the basics of Ansible's architecture, in the next sections, we will dive deeper into each component and how they interact with each other.

Happy Learning!