Comprehensive Architectural Guide to Installing and Configuring Ansible on Ubuntu 20.04

The deployment of modern infrastructure requires a transition from manual, error-prone configurations to automated, repeatable workflows. Ansible stands as a premier solution for software provisioning, configuration management, and application deployment, specifically engineered for developers, system engineers, and network administrators. Developed by the open-source community and sponsored by Red Hat, Ansible leverages an agentless architecture that significantly reduces the overhead associated with managing large-scale environments. By automating repetitive infrastructure tasks, Ansible ensures consistency across environments, thereby saving substantial developer time and eliminating the "it works on my machine" phenomenon. In the context of Ubuntu 20.04, Ansible provides a robust framework for transforming a set of disparate servers into a cohesive, managed fleet.

Foundational Concepts and Architectural Logic

To effectively implement Ansible, one must understand the fundamental components that comprise its operational logic. Ansible is not merely a tool but a system based on specific design principles that prioritize ease of use and a minimal learning curve.

Core Component Definitions

The operational efficiency of Ansible is derived from several key entities:

  • Task: This represents a single unit of action. A task is the smallest building block in Ansible, defining a specific change or check to be performed on a remote host.
  • Playbook: This is a sophisticated orchestration script that stores variables, managed hosts, and tasks. Playbooks are executed in the exact order in which they are written, supporting both synchronous and asynchronous execution patterns.
  • Role: These are collections of tasks grouped under a common name. Roles function as independent components that enable code reusability by grouping common configuration steps into generalized libraries, which can then be invoked within various playbooks.
  • Plugin: This is a piece of code that augments the default functionality of the Ansible engine. Plugins execute on the control node within the Ansible process and are utilized for implementing cache layers, looking up external data sources, or enabling Ansible to respond to specific events.

The Agentless Paradigm

A critical technical distinction of Ansible is its agentless nature. Unlike other configuration management tools that require a proprietary agent to be installed and running on every target machine, Ansible operates via SSH. This means that once the control node is configured and the managed nodes are accessible via SSH, no further software installation is required on the target hosts beyond a usable Python installation. This reduces the attack surface of the managed nodes and simplifies the deployment process.

Infrastructure Prerequisites and Environmental Setup

Before initiating the installation process, a specific environment must be established to ensure seamless communication between the orchestration layer and the target hardware.

Hardware and Connectivity Requirements

A functional Ansible deployment requires a minimum of two distinct machines: 1. Control Node: The machine where Ansible is installed and from which commands are dispatched. 2. Managed Node: The target machine(s) being configured. For comprehensive testing and production-grade setups, utilizing multiple managed nodes is recommended to verify scalability.

Both the control node and the managed nodes must have SSH access enabled. Furthermore, it is a prerequisite that an SSH key be installed on the control node to facilitate secure, passwordless authentication, which is essential for the automation of playbooks.

Security Considerations for Managed Hosts

While it is technically possible to use the root user for accessing and managing nodes, this practice is strongly discouraged. For security and debugging reasons, a dedicated user should be created. Using a non-privileged user who can escalate privileges via sudo is the industry standard for maintaining a secure audit trail and preventing catastrophic accidental changes to the core system.

Step-by-Step Installation and Configuration Process

The following procedure outlines the exhaustive process of transforming an Ubuntu 20.04 system into a functional Ansible control node and integrating it with managed hosts.

Step 1: Configuring Managed Hosts and User Access

The first phase involves preparing the target machines. This ensures that the control node can authenticate and execute commands without manual intervention.

  1. User Creation: Create a new user named ansible on each of the managed nodes.
  2. SSH Connectivity: Establish a secure connection. Once the user is created, the connection can be tested via the terminal: ssh [email protected]
  3. Authentication: The user may be prompted for the password of the ansible user during the initial setup.

Because Ansible is agentless, once the SSH connection is verified, the managed host is immediately ready for orchestration without any additional agent software.

Step 2: Installing Ansible on the Control Node

To ensure the installation of the most current and stable version of Ansible, it is necessary to use an official Personal Package Archive (PPA) rather than relying solely on the default Ubuntu repositories, which may contain outdated versions.

The installation sequence is as follows:

  1. Add the official Ansible PPA to the Ubuntu package manager: sudo apt-add-repository ppa:ansible/ansible
  2. Update the local package lists to recognize the new repository: sudo apt update
  3. Install the Ansible package: sudo apt install -y ansible

Step 3: Developing the Ansible Inventory

The inventory is the heart of the Ansible configuration, as it maps the control node to the managed hosts. This involves defining the targets, their aliases, and the variables required for connection.

Inventory Structure and Variable Assignment

The inventory file allows for the grouping of hosts and the assignment of specific variables. For example, hosts can be assigned individual aliases such as ubuntu, debian, and centos. The public IP addresses of these hosts are mapped using the ansible_host variable.

Furthermore, global variables are defined under the [all:vars] section to ensure consistency across the entire fleet. Key variables include: - ansible_user: Set to "ansible" to match the user created on the managed nodes. - python path: Pointing to the python3 executable, which is located at /usr/bin/python3 on Ubuntu 20.04.

Inventory Verification

To ensure that the syntax of the inventory list is correct and that all managed nodes have been added successfully, the ansible-inventory command is used. Utilizing the -y flag formats the output in YAML, providing a clear configuration tree for review. Command: ansible-inventory --list -y

Operational Validation and Execution

Once the installation and inventory configuration are complete, the system must be validated to ensure the control node can communicate with the managed nodes.

Connection Testing with the Ping Module

The primary method for verifying connectivity is the ansible ping module. This module performs three critical functions: 1 It connects to the host via SSH. 2 It verifies the existence of a usable Python installation on the target host. 3 It returns a "pong" response if the connection is successful.

To target all hosts in the inventory: ansible all -m ping

Advanced Targeting Logic

Ansible allows for granular control over which hosts receive a specific command: - Target Host Groups: If the inventory is divided into groups (e.g., debbased), the command can be restricted to that group: ansible debbased -m ping - Target Specific Aliases: Individual hosts can be targeted using their unique alias defined in the inventory. - Shell Command Passthrough: Ansible can be used to pass raw shell commands directly to the managed nodes for quick diagnostics.

Advanced Implementation: Custom Modules and Cloud Deployment

Beyond the standard pre-built modules—of which there are over 750 official versions categorized in the official documentation—Ansible supports custom modules for specific use cases. A primary example is the integration with Cherry Servers for cloud infrastructure management.

Integrating the Cherry Servers Module

To deploy cloud servers using custom modules, specific environmental configurations are required on the control node: 1 Install the cherry-python package. 2 Export the CHERRYAUTHTOKEN for authentication. 3 Download the required Python scripts (local modules) into the library/ directory of the project.

Case Study: Cloud Server Deployment Playbook

The following playbook demonstrates the deployment of a cloud server using the cherryservers_server module. This requires a local connection since the module queries the API from the control node.

Playbook Configuration: - Connection: local - Hosts: localhost - Task: Deploy new server - Module: cherryservers_server - Hostname: the-coolest-machine - Plan ID: 161 (corresponds to E5-1620v4 server plan) - Project ID: 79617 - Image: Ubuntu 20.04 64bit - Region: EU-East-1 - State: present - Count: 1

The playbook is executed using the following command: ansible-playbook deploy-cherry-server.yaml

Upon execution, the console output confirms the successful initiation of the cloud server deployment process, provided there are no failed tasks.

Technical Specification Summary

The following table outlines the key technical requirements and configurations for an Ansible deployment on Ubuntu 20.04.

Component Requirement/Value Purpose
OS Ubuntu 20.04 Base Operating System
Repository ppa:ansible/ansible Source for latest Ansible version
Python Path /usr/bin/python3 Execution environment for modules
Connection Protocol SSH Agentless communication
User ansible (non-root) Security and access management
Inventory Format YAML (via -y flag) Structured host management
Primary Module for Test ping Connectivity and Python verification

Final Technical Analysis

The implementation of Ansible on Ubuntu 20.04 transforms the administrative approach from a manual "craftsman" model to an "industrialized" automation model. By utilizing the PPA for installation, the administrator ensures access to the latest modules and security patches. The shift toward an agentless architecture, powered by SSH and Python, eliminates the lifecycle management burden of agents on target nodes.

The strategic use of roles and playbooks allows for the creation of a modular infrastructure where common configurations—such as security hardening or database installation—can be packaged as reusable libraries. When integrated with custom modules, such as those provided by Cherry Servers, Ansible extends its reach from simple configuration management to full-scale cloud orchestration. The ability to verify the inventory through YAML output and validate connectivity via the ping module ensures that the infrastructure is predictable and stable before the execution of complex deployment playbooks.

Sources

  1. How to Install Ansible on Ubuntu 20.04 | 7 Steps [+ Configuration]
  2. How to Install and Configure Ansible on Ubuntu 20.04 - Mantas Levinas

Related Posts