X
Collapse
-
How to Install Ansible on Ubuntu 24.04
In the digital world, a key concern for most organizations is how to control multiple servers and streamline the process to make it easy for their administrators. Luckily, there are different configuration management systems, such as Ansible, that make it easy and convenient to automate these tasks.
With an automation tool such as Ansible, you can perform tasks such as software deployment and configuration management from one Ansible control host without having to log in to each target server. Ansible is a free automation tool, and if you are new to it, stick around as this post shares everything you need to install it on Ubuntu 24.04.
Installation and Configuration of Ansible on Ubuntu 24.04
To work with Ansible, you need an Ansible control host, which is our Ubuntu 24.04, and one or more Ansible hosts. The Ansible hosts are the target machines that you want to automate from one control host. For these hosts, we will use SSH to connect to them through SSH key pairs. Let’s break down the process into understandable steps.
Step 1: Install Ansible on Your Control Host
On our Ubuntu 24.04(Noble Numbat), that’s where we will install Ansible. First, let’s quickly update and upgrade our system.
$ sudo apt update && sudo apt upgrade
Before we can install Ansible using the APT, let’s check the available version in its repository using the command below.
$ sudo apt-cache policy ansible
We can now run our install command to fetch and install Ansible from our Ubuntu repository.
$ sudo apt install ansible
Once Ansible installs, check the version to confirm that your installation was successful.
$ ansible --version
You now have Ansible installed on your system. However, we must configure it to set our control host.
Step 2: Setting Up SSH Keys
Ansible uses SSH to connect to the Ansible hosts when running any tasks from the Ansible control host. As such, we must copy our Ansible control host’s SSH public key to our Ansible hosts for seamless connection without requiring any passwords.
The first step is to generate the SSH key pair on our Ansible control node.
$ ssh-keygen
You can select a different location to save the key or go with the default location. Moreover, you can set a passphrase for authentication or not. Once you’ve set your preferences, your SSH key pair will be generated.
We then must copy the public key to our Ansible hosts. First, ensure you have the IP address of the target host and the username. Once you do so, we will copy the public key using ssh-copy-id with the following command.
$ ssh-copy-id username@ip_address
You will get a message asking you whether you wish to proceed and authenticate the connection. Type ‘yes’ to continue.
Once you enter the password for your remote host, you will get an output showing that the key has been added successfully.
While still connected to the remote machine, open the SSH configuration file and disable password authentication, as in the image below.
$ sudo nano /etc/ssh/ssh_config
Save the file and log out of your remote host. The next time you try to log in, you won’t be prompted to enter your password, as the SSH key pairs will be used for authentication.
Step 3: Configuring Your Ansible Control Node
So far, we’ve installed Ansible and set up SSH keys for the connection. The other step is to configure our Ansible control node by specifying the IP addresses of all the Ansible hosts that we want to control. To do so, we must create an inventory file containing the host details.
Create your inventory file and name it according to your preference. We’ve stored our “ansible-hosts” inventory file in our current directory. Inside the file, add the details of the servers you wish to control and ensure that you’ve set up each server’s SSH keys as we did in the previous step.
Lastly, save your inventory file and exit the text editor.
To verify that our Ansible inventory file exists, use the below command and replace the “ansible-hosts’ with the path to where you’ve saved your inventory file.
$ ansible-inventory --list -i ./ansible-hosts -y
You will get an output showing the infrastructure of the added Ansible host(s).
Step 4: Test the Ansible Connection
The last step involves verifying that our connection works and that we can access and control the added Ansible hosts from our Ansible control node. If the connection was well set up, we should be able to run commands from our control node.
For instance, let’s try running a ping command and see if the hosts can connect. In the below command, replace ‘linuxhint’ with the username of your target Ansible host and replace the inventory file to match the path where you’ve saved yours.
$ ansible all -i ./ansible-hosts -m ping -u linuxhint
The above output shows a success message, confirming that we have control of our Ansible hosts. You can verify this further by running ad-hoc commands. For instance, let’s check the disk usage by running the below command.
$ ansible all -i ./ansible-hosts -a “df -h” -u linuxhint
That’s it! We’ve managed to install and configure Ansible on Ubuntu 24.04.
Conclusion
Installing Ansible on Ubuntu 24.04 is easy when you have a clear guide to follow. This post acts as a clear guide to help you easily and quickly install and configure Ansible on Ubuntu 24.04. We’ve shared all the steps and demonstrated that our Ansible connection works as expected.
More...Tags: None
Posting comments is disabled.
Categories
Collapse
Article Tags
Collapse
There are no tags yet.
Latest Articles
Collapse
-
by KasimbaI don’t like my prompt, i want to change it. it has my username and host, but the formatting is not what i want. This blog will get you started quickly on doing exactly that.
This is my current prompt below:
To change the prompt you will update .bashrc and set the PS1 environment variable to a new value.
Here is a cheatsheet of the prompt options:
You can use these placeholders for customization:
\u – Username
...-
Channel: Articles
01-06-2025, 01:15 AM -
-
by KasimbaIn this post I will show you how to install the ZSH shell on Rocky Linux. ZSH is an alternate shell that some people prefer instead of BASH shell. Some people say ZSH has better auto-completion, theme support, and plugin system. If you want to give ZSH a try its quite easy to install and give it a try. This post is focused on the Rocky Linux user and how to install ZSH and get started with its usage.
Before installing anything new, it’s good practice to update your system packages:...-
Channel: Articles
12-25-2024, 02:01 AM -
-
by Kasimba
by George Whittaker
Introduction
In the world of operating systems, Windows has long held the lion’s share of the market. Its user-friendly interface and wide compatibility have made it the default choice for many. However, in recent years, Linux has steadily gained traction, challenging the status quo with its unique offerings. What was once considered the domain of tech enthusiasts and developers is now...-
Channel: Articles
12-21-2024, 06:52 AM -
-
by KasimbaOverview of NGINX and Apache
NGINX and Apache are leading web server solutions utilized for hosting websites and web applications. Apache, developed by the Apache Software Foundation, offers robust configuration options and extensibility. NGINX, created by Igor Sysoev, is known for its efficiency in handling numerous concurrent connections with low resource utilization. Both servers function not only as HTTP servers but also as reverse proxies, load balancers, and more.
What is
...-
Channel: Articles
12-21-2024, 03:54 AM -
-
by KasimbaHi everyone, I hope you are enjoying the BETA so far! This release introduces new features, tools, and artwork, so we anticipate a good number of bug reports. Every single fix helps us refine and improve the final release. Your feedback during the BETA phase is extremely important to us. Linux Mint 22.1 is our […]
More...-
Channel: Articles
12-16-2024, 11:50 AM -
-
by Kasimba
by George Whittaker
Introduction
Remote access is a cornerstone of modern IT infrastructure, enabling administrators and users to manage systems, applications, and data from virtually anywhere. However, with great power comes great responsibility—ensuring that remote access remains secure is paramount. This is where OpenSSH steps in, providing robust, encrypted communication for secure remote management....-
Channel: Articles
12-13-2024, 10:31 PM -