Simplifying System Management: Installing Ansible on Ubuntu 22.04
In this guide, we’ll walk through the process of installing and configuring Ansible on Ubuntu 22.04. Ansible, an agentless configuration management tool, facilitates the management of numerous client machines effortlessly. It operates and communicates over SSH, eliminating the need for any additional software on the client side.
Ansible Configuration Management Tool
Scenario:
– Master Server: 10.80.253.11 / master
– Client Server 1: 10.80.253.12 / slave1
– Client Server 2: 10.80.253.13 / slave2
Machine IPs and names can be added to /etc/hosts for easy reference.
Installing Ansible on Ubuntu 22.04
To install Ansible on Ubuntu 22.04, configuration of the PPA (Personal Package Archive) is required for the latest version. Run the following commands on the master server:
Verifying Ansible Installation:
To confirm the successful installation and check the Ansible version, execute:
This should display information about the Ansible version and configuration.
Ansible Hosts Configuration:
Ansible requires information about remote machine names and IP addresses, stored in the host file. The default path is /etc/ansible/hosts. Edit or create a new file and append the server IP or name. For example:
Add the following:
Save the file.
Setting Up SSH Keys
SSH keys need to be set up and copied to all client machines for seamless communication without password prompts. Click here to learn how to configure passwordless login between the server and client using SSH.
Executing Simple Ansible Commands
Checking Ping Command
To check the ping command and ensure communication with client machines, run:
A successful response indicates that all client machines can communicate with the server.
Running Additional Ansible Commands
Execute various commands to check system information, service status, uptime, processes, file contents, and CPU information on all Ansible client machines.
Certainly! Here’s a brief description for each of the Ansible commands:
Check Memory Usage:
This command uses the free command to display the memory usage (in megabytes) on all servers specified in the Ansible inventory.
Check Disk Space:
The df command is employed to show the disk space usage. The -h flag makes the output human-readable, providing information on available, used, and total disk space.
Restart SSH Service:
This command restarts the SSH service on all servers specified in the Ansible inventory. It’s a typical example of managing services remotely.
Check Uptime:
The uptime command is used to display the current system uptime, the number of users logged in, and system load averages on the specified servers.
Check SSH Processes on a Specific Server:
This command looks for processes containing “ssh” in their details on the server named “slave1.” It’s a way to inspect running SSH-related processes.
Check Timezone Configuration on a Specific Server:
This command prints the content of the /etc/timezone file on “slave1,” providing information about the configured timezone on that server.
Check CPU Information on a Specific Server:
Here, the command retrieves and displays detailed information about the CPU on “slave1” by reading the /proc/cpuinfo file.
These commands demonstrate Ansible’s flexibility in remotely executing tasks ranging from inspecting system metrics to managing services and configurations across multiple servers. These commands provide information about memory usage, disk space, service restarts, uptime, running processes, file content, and CPU details.
These steps have been used to configure the Ansible server and clients on Ubuntu 22.04. We will explore the creation and operation of Ansible playbooks in the upcoming article. Stay tuned for more!