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 Kasimba
by George Whittaker
Introduction
Qualitative data analysis (QDA) is a cornerstone of research across various fields, from social sciences to marketing. It involves uncovering patterns, themes, and meanings within non-numerical data such as interviews, focus groups, and textual narratives. In this era of digital tools, MAXQDA stands out as a premier software solution for QDA, empowering researchers to organize...-
Channel: Articles
11-21-2024, 11:31 PM -
-
by Kasimba
by german.suarez
Introduction
In today’s fast-paced digital landscape, ensuring the availability and performance of applications is paramount. Modern infrastructures require robust solutions to distribute traffic efficiently and maintain service availability even in the face of server failures. Enter HAProxy, the de facto standard for high-performance load balancing and failover.
This article...-
Channel: Articles
11-21-2024, 03:00 PM -
-
by KasimbaArch Linux hasn't had a license for any package sources (such as PKGBUILD files) in the past, which is potentially problematic. Providing a license will preempt that uncertainty.
In RFC 40 we agreed to change all package sources to be licensed under the very liberal 0BSD license. This change will not limit what you can do with package sources. Check out the RFC for more on the rationale and prior discussion.
Before we make this change, we will provide contributors with...-
Channel: Articles
11-19-2024, 09:21 AM -
-
by Kasimba
by George Whittaker
Introduction
In the world of cybersecurity and software development, binary analysis holds a unique place. It is the art of examining compiled programs to understand their functionality, identify vulnerabilities, or debug issues—without access to the original source code. For Linux, which dominates servers, embedded systems, and even personal computing, the skill of binary analysis is...-
Channel: Articles
11-18-2024, 07:10 PM -
-
by KasimbaDebian and Ubuntu are two popular Linux distributions. In this deep dive we will guide you on the key differences between them from perspective of both corporate enterprise and personal productivity or pleasure usage. After reading this blog post you should be in a better position to decide to select Ubuntu or Debian.
Stewardship, Licensing, Community and Cost
Where as Debian is 100% fully committed to free software as defined by the Debian Free Software Guidelines, Ubuntu is created...-
Channel: Articles
11-17-2024, 08:30 PM -
-
by Kasimba
by George Whittaker
Introduction
In the digital age, data loss is a critical concern, and effective backup and recovery systems are vital for any Debian system administrator or user. Debian, known for its stability and suitability in enterprise, server, and personal computing environments, offers a multitude of tools for creating robust backup and recovery solutions. This guide will explore these solutions,...-
Channel: Articles
11-13-2024, 05:30 PM -