How to Install Ansible on Ubuntu 23.04 Server

How to Install Ansible on Ubuntu 23.04 Server. In this post, we introduce Ansible, its major benefits then move on to the Ansible installation steps on Ubuntu 23.04 server.

In order to achieve the goals of modernization and digital transformation, useful and relevant automation is required. In today’s changing situations, a new management solution is required to improve the IT infrastructure’s scalability, reliability, and speed.

As every organization is now a digital organization. Technology drives innovation, and if you get applications to customers more quickly, you have a competitive edge.

In the past, this required a great deal of time, energy, and intricate planning. Today, however, there is Ansible, a simple but powerful IT automation engine that is being used by hundreds of businesses to remove complexity from their systems and speed up their DevOps efforts.

What is Ansible?

How to Install Ansible on Ubuntu 23.04 Server

Ansible is a software tool that makes it easy to automate computer help across different platforms. Application deployment, cloud provisioning, intra service orchestration, configuration management, upgrades on workstations and servers, and pretty much anything else a systems administrator performs weekly or daily all be accomplished using this tool.

With no need for agent software or other security infrastructure, Ansible may be quickly and easily deployed. Ansible is a powerful tool for developers to utilize in their day to day work, and it’s also at the forefront of automation, systems management, and DevOps.

You don’t need to know how to code to use Ansible, and yet you use it to setup not just one machine, but possibly a whole network. Ansible documentation can be read by humans. As well, Ansible files can be read and understood by anybody, regardless of their level of technical expertise.

Ansible’s various simplifications suggest it may provide multiple advantages. Let’s have a better look!

1. Easy to Understand

When discussing the advantages of Ansible, its ease of use consistently comes up first. The clarity is designed for both experienced users and newcomers. Because of how simple it is to pick up, users become productive using Ansible in no time. Documentation for Ansible is both thorough and straightforward.

This means that you quickly absorb the fundamentals of Ansible’s operation logic and workflow. Due to the absence of a dependency structure, it is possible that Ansible tasks run in order and halt when an issue is detected. Therefore, even in the early stages of understanding Ansible, troubleshooting is much simpler.

2. Agentless function

All contact between the master and agents is handled by Ansible through Standard SSH or the Paramiko module. Essential to the management of nodes is the Paramiko module, a Python implementation of SSH2. Therefore, Ansible requires no agents to be deployed on remote systems for management purposes. Thus, Ansible drastically reduces maintenance costs and performance deterioration.

3. YAML creates playbooks

Playbooks are simple to read and update. The Playbooks themselves are written in YAML, which is a straightforward markup language, and the configuration process is simple.

4. Simple Python Language

Ansible’s ease of use is a result of the language in which it is written. Ansible is built on Python, a language easy to understand. Since Python libraries are included by default on most Linux distributions, this facilitates setting up and executing Ansible.

Ansible modules enhance its capabilities are also intriguing. Not forgetting, that any programming language may be used to create Ansible modules. In this instance, the module’s return of data in JSON format is the crucial issue to address.

5. Ansible Galaxy

In order to find, reuse, and share Ansible related material, you may use a portal called Ansible Galaxy. The most useful feature of Ansible Galaxy is undoubtedly the ability to download and reuse roles for the purpose of setting up applications and servers.

How to Install Ansible on Ubuntu 23.04 Server

This section teaches you how to install Ansible and working with Ansible basic commands.


  • Three servers running Ubuntu 23.04.
  • We use one server for the Ansible host and another for the target servers.

Update All Servers

First, it is essential to update and upgrade all system packages to the latest version. Perform the update process using the following command.

					apt update -y
apt upgrade -y


Once the update process is complete, you will need to restart your server to apply the changes.


Add Ansible Repository

By default, the latest version of the Ansible package is not included in the Ubuntu 23.04 main repository. So it is recommended to add the Ansible repository to get the latest version.

First, install all the required dependencies using the following command.

					apt install software-properties-common gnupg2 wget curl -y

Once all the dependencies are installed, add the Ansible official repository with the following command.

					add-apt-repository --yes --update ppa:ansible/ansible

After adding the Ansible repository, update the repository cache using the following command.

					apt update

Install Ansible on Ansible Host

At this point, the Ansible repository is added and up to date. Install it now to the latest version of Ansible with the following command.

					apt install ansible -y

Once the Ansible package is installed, verify the Ansible version using the following command.

					ansible --version

You see the Ansible version on the following screen.

Configure SSH on Ansible Host

Next, you need to create an SSH key and set up password-less SSH authentication between the Ansible host and target hosts. First, generate the SSH key pair using the following command.

					ssh-keygen -t rsa

Answer all the questions as shown below to generate an SSH key.

Next, copy the generated key to the target hosts using the following command.

					ssh-copy-id root@first-target-host
ssh-copy-id root@second-target-host

At this point, the Ansible host can connect to target hosts via SSH without providing a password.

Create an Ansible Inventory File

Next, you will need to create an Ansible inventory file to define all target hosts that you want to manage from the Ansible host machine. Create it with the following command.

					nano /etc/ansible/hosts

Add your target server’s information as shown below.

server1 ansible_host=first-remote-host-ip
server2 ansible_host=second-remote-host-ip


Save and close the file then verify your inventory file using the following command.

					ansible-inventory --list -y

You see your added hosts in the following screen.

Working with Ansible Ad-hoc Commands

At this point, Ansible is installed and configured to control and manage both target hosts. Now, it’s time to use Ansible ad-hoc commands to manage target hosts via cli.

First, check the connectivity of all remote hosts that are defined in the servers group using the following command.

					ansible -m ping servers -u root

If the connection is successful, you see the following screen.

To check the server1 connectivity, run the following command.

					ansible -m ping server1 -u root

If you want to check the connectivity of all remote hosts, run the following command.

					ansible -m ping all -u root

With Ansible, you can also check the CPU, Memory, and Disk usage via simple commands. For example, to check the memory usage of all servers, run the following command.

					ansible all -a "free -m" -u root

You should see the memory usage on the following screen.

To check the disk usage of server1, run the following command.

					ansible server1 -a "df -h" -u root

You should see the server1 disk usage on the following screen.

Ansible also allows you to install and manage packages on remote servers. For example, to install the Nginx package on server1, run the following command.

					ansible -m shell -a 'apt install -y nginx' server1

You should see the following screen.

Now, verify the installed Nginx version using the following command.

					ansible -m shell -a 'nginx -V' server1

You should see the Nginx version on the following screen.

Thank you for taking time to read How to Install Ansible on Ubuntu 23.04 Server. Let’s conclude.

How to Install Ansible on Ubuntu 23.04 Server Conclusion

In this guide, we talked you through Ansible installation steps and created Ansible inventory to define all target hosts. We then showed you how to use Ansible ad-hoc commands to manage target servers. I hope you can now use Ansible in your infrastructure to manage and control multiple servers from the central place.

As a last thought,  Ansible delivers a comprehensive, but easy-to-use, toolkit for configuration management and automation. Ansible’s potential is shown by the wide range of its features, which include provisioning, orchestration, application deployment, and security and compliance. These features of Ansible may easily be adapted into a powerful DevOps suite. Improving Ansible’s strengths is crucial to the framework’s future success.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x