Ansible: Architecture & Components

Ansible has a modular architecture designed for IT automation and configuration management. It consists of several core components that make it an efficient and flexible tool for automating tasks.

Ansible Architecture Diagram

The architecture can be visualized as:

[Control Node] --(SSH)--> [Managed Nodes]
    |
    | Inventory
    | Playbooks
    | Modules
    |
  [Ansible Tower (Optional)]  
    |
    |- Role-Based Access Control
    |- Workflow Automation
    |- Web Interface & Dashboard
    |- Centralized Logging

Ansible Engine:

  • Control Node: Manages automation and runs playbooks.

  • Managed Nodes: Machines managed by Ansible, accessed via SSH (agentless).

  • Inventory: File listing managed hosts.

  • Playbooks: YAML scripts defining tasks.

  • Modules: Reusable scripts to perform tasks on managed nodes.

  • Roles: Organized, reusable components of playbooks.

Ansible Tower (Enterprise version):

  • Web UI & Dashboard: Manage playbooks and view jobs.

  • RBAC: Role-based access for different users.

  • Job Scheduling: Automate routine tasks at specified times.

  • Workflows: Create complex automation sequences.

  • API & Notifications: Integrate with other tools and send alerts.

Ansible Engine handles core automation, while Ansible Tower adds a UI, advanced control, and enterprise features.

Reviewing the components and their configuration on the Ansible control node (server):

Ansible itself doesn’t have a visualized architecture diagram built into it, but you can explore its architecture by reviewing the components and their configuration on the Ansible control node (server). Here are some key steps to understand the architecture:

  1. Check Default or Root Directory of Ansible:
cat /etc/ansible/

  1. Explore Configuration File:
  • The configuration file (ansible.cfg) defines settings for how Ansible should run, including paths to inventory files and SSH settings.

  • You can find it at /etc/ansible/ansible.cfg or a custom path in your project.

cat /etc/ansible/ansible.cfg

  1. Check Inventory File:
  • The inventory file contains the list of managed nodes.

  • You can view it using

cat /etc/ansible/hosts
cat /etc/ansible/hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers:

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group:

## [webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110

# If you have multiple hosts following a pattern, you can specify
# them like this:

## www[001:006].example.com

# You can also use ranges for multiple hosts: 

## db-[99:101]-node.example.com

# Ex 3: A collection of database servers in the 'dbservers' group:

## [dbservers]
##
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57


# Ex4: Multiple hosts arranged into groups such as 'Debian' and 'openSUSE':

## [Debian]
## alpha.example.org
## beta.example.org

## [openSUSE]
## green.example.com
## blue.example.com
  1. List Available Modules:

You can see all the available modules that Ansible can use:

ansible-doc: This is a command used to access the documentation for Ansible modules. It provides detailed information about each module, including its parameters and usage.

ansible-doc -l
ubuntu@ip-172-31-30-162:~$ ansible-doc -l
amazon.aws.autoscaling_group                ; Create or delete AWS AutoScaling Groups (ASGs)
amazon.aws.autoscaling_group_info           ; Gather information about EC2 Auto Scaling Groups (ASGs)
amazon.aws.aws_az_info                      ; Gather information about availability zones in AWS
amazon.aws.aws_caller_info                  ; Get information about the user and account being used
amazon.aws.aws_region_info                  ; Gather information about AWS regions
amazon.aws.backup_plan                      ; Manage AWS Backup Plans
amazon.aws.backup_plan_info                 ; Describe AWS Backup Plans
amazon.aws.backup_restore_job_info          ; List information about backup restore jobs
amazon.aws.backup_selection                 ; Create, delete and modify AWS Backup selection
amazon.aws.backup_selection_info            ; Describe AWS Backup Selections
amazon.aws.backup_tag                       ; Manage tags on backup plan, backup vault, recovery point
amazon.aws.backup_tag_info                  ; List tags on AWS Backup resources
amazon.aws.backup_vault                     ; Manage AWS Backup Vaults
amazon.aws.backup_vault_info                ; Describe AWS Backup Vaults
amazon.aws.cloudformation                   ; Create or delete an AWS CloudFormation stack
amazon.aws.cloudformation_info              ; Obtain information about an AWS CloudFormation stack
amazon.aws.cloudtrail                       ; Manage CloudTrail (create, delete, update)
amazon.aws.cloudtrail_info                  ; Gather information about trails in AWS CloudTrail
amazon.aws.cloudwatch_metric_alarm          ; Create/update or delete AWS CloudWatch metric alarms
amazon.aws.cloudwatch_metric_alarm_info     ; Gather information about the alarms for the specified metric
amazon.aws.cloudwatchevent_rule             ; Manage CloudWatch Event rules and targets
amazon.aws.cloudwatchlogs_log_group         ; Create or delete log group in CloudWatchLogs
amazon.aws.cloudwatchlogs_log_group_info    ; Get information about log group in CloudWatchLogs
amazon.aws.cloudwatchlogs_log_group_metric_filter ; Manage CloudWatch log group metric filter
amazon.aws.ec2_ami                          ; Create or destroy an image (AMI) in EC2
amazon.aws.ec2_ami_info                     ; Gather information about EC2 AMIs
amazon.aws.ec2_eip                          ; Manage EC2 elastic IP (EIP) addresses
amazon.aws.ec2_eip_info                     ; List EC2 EIP details
amazon.aws.ec2_eni                          ; Create and optionally attach an Elastic Network Interface (ENI)
amazon.aws.ec2_eni_info                     ; Gather information about EC2 ENI interfaces in AWS
amazon.aws.ec2_import_image                 ; Manage AWS EC2 import image tasks
amazon.aws.ec2_import_image_info            ; Gather information about import virtual machine tasks
amazon.aws.ec2_instance                     ; Create and manage EC2 instances
amazon.aws.ec2_instance_info                ; Gather information about EC2 instances in AWS
amazon.aws.ec2_key                          ; Create or delete an EC2 key pair
amazon.aws.ec2_key_info                     ; Gather information about EC2 key pairs in AWS
amazon.aws.ec2_metadata_facts               ; Gather facts (instance metadata) about remote hosts within EC2
amazon.aws.ec2_security_group               ; Maintain an EC2 security group
amazon.aws.ec2_security_group_info          ; Gather information about EC2 security groups in AWS
amazon.aws.ec2_snapshot                     ; Create a snapshot from an existing volume

Example:

ansible-doc ec2_instance

This command will display detailed documentation about the ec2_instance module, including parameters, examples, and return values.

Ansible Components:

Pic Credit: @Govardhana Miriyala Kannaiah Thank you!

Here's a brief explanation of the components shown in the image:

  1. /etc/ansible/: The main directory for Ansible files and configurations.

  2. ansible.cfg: The configuration file that contains the main settings for Ansible, such as inventory paths, connection settings, etc.

  3. inventory: This directory contains the list of all hosts that Ansible manages. It may have files like hosts.ini.

  4. hosts.ini: Contains hostnames or IP addresses of machines to be managed by Ansible.

  5. playbooks: Directory for storing playbooks, which are YAML files that define tasks and automation sequences.

  6. group_vars: Stores variables specific to groups of hosts, allowing configurations to be applied to multiple nodes.

  7. host_vars: Stores variables for individual hosts, enabling specific settings per managed node.

  8. ansible_plugins: Holds custom plugins to extend Ansible’s functionality.

  9. modules: A subdirectory that contains custom Ansible modules for performing tasks.

  10. ping: A specific module used to test connectivity between the control node and managed hosts.

  11. templates: Contains Jinja2 templates for configuration files. These templates can be dynamically populated using variables.

  12. roles: Used to organize playbooks into reusable components with a standardized structure, including tasks, handlers, variables, and files.

  13. files: Stores static files that are used or deployed by playbooks.

0
Subscribe to my newsletter

Read articles from Subbu Tech Tutorials directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Subbu Tech Tutorials
Subbu Tech Tutorials