Get 50% Discount Offer 7 Days


Contact Info

Chicago 12, Melborne City, USA

+88 01682648101

[email protected]

Tutorial Configure and Use Ansible on AlmaLinux 8.5

Ansible is known as a free, open-source automation tool that allows system administrators to configure and control hundreds of nodes from a central server without having to install any agents on the nodes. This tool is a better management solution than Poppet and Chef due to its easy installation and use. You will learn How to Configure and Use Ansible on AlmaLinux 8.5 by studying this article. So keep studying carefully.

Introduction to Ansible

Ansible is an automated tool and open-source platform, used for IT tasks such as managing configuration, deploying applications, setting up in-service, and delivering. Automation is very important these days, and IT environments are very complex and usually need to be scaled very quickly so that system administrators and developers can continue the process even if they need to do things manually. Notice that to use this helpful tool on distributions like AlmaLinux you can purchase Cheap Linux VPS servers from our site.

Automation not only simplifies complex tasks, but also makes developers’ jobs more controllable, and allows them to focus on other tasks that add value to an organization. In other words, it saves time and increases efficiency. Ansible is rapidly rising in the list of world automation tools.

How to Install Ansible on AlmaLinux 8.5

First, you need to make sure the system is up to date using the following commands:

sudo dnf update
sudo dnf upgrade

Then you need to install EPEL using the following command:

sudo dnf install epel-release

Then, use the following commands to install Python 3 and run other dependencies:

sudo dnf module install python3.8
sudo alternatives --config python

In this step, install Ansible from the official AlmaLinux repository:

sudo dnf install ansible

To install Ansible, you need to run the following commands:

sudo pip3 install setuptools-rust wheel
sudo pip3 install --upgrade pip
sudo python3 -m pip install ansible

When done, it is time to confirm the installation using the following command:

ansible –version

How to Configure Ansible on AlmaLinux 8.5

In the first step of this step, to configure Ansible, it is necessary to install OpenSSH-server using the following commands:

sudo dnf install openssh-server
sudo systemctl enable ssh

Enter the following command to allow port 22 in the firewall:

sudo ufw allow 22

You can use the following commands for RHEL or CentOS Linux VPS:

sudo dnf install openssh-server
sudo systemctl enable sshd

You should allow port 22 in the firewall:

sudo firewall-cmd --zone=public --permanent --add-port=22/tcp

To perform these steps, you must have three servers: Ubuntu, Debian, and CentOS:

Ubuntu – server_IP
CentOS – server_IP
Debian – server_IP

How to Use Ansible on AlmaLinux 8.5

In the continuation of this article, we intend to teach you step-by-step How to Use Ansible on AlmaLinux 8.5.

How to Generate SSH Keys on Ansible Installed AlmaLinux

To install the package or deploy it on the target remote server, create a pair of SSH keys on the localhost and then press them on each remote server so that you can manage them using SSH. Type the command and press the Enter key several times until the keys are generated:


How to Copy SSH keys to Remote or Target Servers

Press the key created in almaLinux to the remote servers that you want to configure or manage. You need to know the username of the remote server or use the default root user.

Tip: Replace Linda with sudo users on remote servers or use the default root and replace the IP address with the server address.

ssh-copy-id linda@Ubuntu – server_IP
ssh-copy-id linda@CentOS – server_IP
ssh-copy-id linda@Debian – server_IP

Run the following command on each server so that you can run sudo commands on them using Ansible without entering a password:

echo "$(whoami) ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/$(whoami)

How to Inventory Files for Remote Hosts

In Ansible, create a file that defines the entire remote host or target system that you want to manage. Also create a group of hosts, for example, a group is a web server that only includes a remote system that runs some web servers such as Apache, and another group can be a Mysql group running a Database server and so on. The Inventory file is also important because it uses the commands, modules, and tasks in a playbook. Now as you have three remote servers in this tutorial, add them to the Ansible host file:

sudo dnf install nano -y
sudo nano /etc/ansible/hosts

If you do not want to create a group, put your remote server IP address or domain name in the file, and specify a group before adding IP addresses. Edit the default values of the Ansible inventory file that already contains samples, or add your own samples at the bottom of the file. In this section, add two servers to a host group identified by the web servers, and one server is defined as an individual.

They are in a group called a web server. The advantage of creating a group is that you can issue a command to a complete set of servers defined in that particular group of hosts.

Inventory with custom SSH port

If you are using a server that does not have a default 22 SSH port, for example, a server running on a Docker, you can also define it by its IP address:

your_IP_address ansible_user=remote-server-username ansible_port=49153

Tip: In the above command, replace the IP address, remote-server username, and port number and add it to the inventory file.


To save the file, just press Ctrl + X, Type “-y” and press Enter.

How to Ping all added Remote Servers on AlmaLinux

Once you have successfully created the inventory file, check if Ansible can ping all the added servers for it. To ping group server:

ansible -m ping group-name


ansible -m ping web-servers

To ping a single server:

ansible -m ping ip-address


ansible -m ping your_IP_address

Finally, you can type the following command to ping all:

ansible -m ping all

Ansible Commands to Install Packages from Remote Servers

In this section, we are going to explain common Ansible commands to install packages or retrieve info from remote servers. Suppose you want to install the Apache web server on a group of servers that you have defined in the Inventory file. Use a web server, as we have already mentioned here, you can use any name you give to your server group.

Command Syntax 

You can use the following command as a syntax command:

ansible -b --become-method = sudo -m shell -a 'command to execute' web servers

For example, running an update and installing the Apache server on Debian and Ubuntu remote systems simultaneously:

ansible -b --become-method=sudo -m shell -a 'apt update' webservers

Installing Apache

You can use the following command to install Apache:

ansible -b --become-method=sudo -m shell -a 'apt install -y apache2' webservers

To execute the same command above for all defined remote PCs:

ansible -b --become-method=sudo -m shell -a 'apt install -y apache2 ' all

For non-grouped hosts, you can use their IP address, for example, the following command:

ansible -b --become-method=sudo -m shell -a 'apt install -y apache2' your_IP_address

Also use other commands that do not require sudo, such as working time check:

ansible -m command -a "uptime" group-name/ip-adress

The command can be used for other purposes, just replace the uptime with the command you want to run on the remote server and rename the group/IP address.


As we mentioned above, Ansible is an automation tool. We concentrate on this tool to familiarize you with the features of Ansible and learn how to install and configure it on AlmaLinux. This automation platform has grown over the years to provide powerful automation solutions that work for IT operators, managers, and decision-makers in a variety of technology fields. We hope you find this tutorial useful. Share your comments with us via the form below.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Share this Post

Leave a Reply

Your email address will not be published. Required fields are marked *