How to install Ansible on Ubuntu 20.04?
Overview
Ansible allows users to build systems for configuration management to help operations teams and administrators manage large numbers of servers. They enable you to operate numerous systems automatically from a single location.
Although there are numerous well-known configuration management tools for Linux systems, like Chef and Puppet, these are frequently more complicated than many people need or want. Ansible is an excellent alternative to these choices since it provides an architecture that uses SSH to carry out automation operations and YAML files to describe provisioning details without the need for specific software to be required on nodes.
In this tutorial, we will learn how we can install Ansible on a system equipped with Ubuntu version 20.04.
Prerequisites
There are certain prerequisites that need to be met before you begin:
Ubuntu equipped system
A regular root user
Internet connection
Knowledge of Command Line Interface(CLI)
Get Started
Step1: Configuring Control Node for Ansible
Log in as root and create a new (non-root) user, then grant them administrative rights and an SSH key pair to configure the Ansible control node.
Include a root user and administrator-level control node. To add a user, type the following command:
Establish a strong password for the account and, if applicable, give answers to questions prompted by the system. If there are any options you don't want to complete right now, hit Enter to skip them.
It immediately creates a new user account. The newly established account should now be given administrative rights. Type the command specified to grant superuser permissions:
Now, the newly created user can now use administrative operations using sudo command.
Step 2: Setting up of SSH Key pair
Use the following code on the terminal which has the control node and hit enter:
If you've already set up an SSH key pair, the system shows the output shown below. You can choose whether you want to replace the current SSH Key pair or not.
Note: The prior SSH key pair is rendered unusable by overwriting. Before you confirm, ensure that you no longer require the previous keys because this step is irreversible.
Next, you are asked for a passphrase. It is strongly suggested to implement a passphrase that is secure in order to avoid security problems that can occur. The output will be like the example below:
Step 3: Ansible Host Configuration
Ansible hosts are remote servers which can be controlled and monitored by an Ansible control node.
Use 'ssh-copy-id' procedure which is the easiest way to set up an SSH public key:
Step 4: Ansible Installation
Ensure the packages are updated on the system. Use the given command to update all the packages:
Next, enter the command given below to install Ansible:
The installation process will ask you to enter Y for confirmation to continue, post which the remaining steps will be completed automatically.
After installation, now we can manage remote hosts through the Ansible control node.
Step 5: Inventory Files Configuration
To enable communication between Ansible and remote hosts, we need to configure an inventory file for those hosts.
Note: Inventory file includes all the details regarding the remote hosts which you can control using the Ansible control node. You can divide up to a few hundred hosts into distinct groups and subgroups and define variables unique to each group you created.
Use the following command to view the inventory file:
The inventory file is now open, and you can start to add remote hosts which the control node will look after. The standard Ansible inventory file begins with broad guidelines and illustrations for creating a list of remote hosts. To add additional hosts and categorize them, scroll to the file's bottom.
The inventory file can be verified once more after it has been set up using the below command:
An output showing the hosts' infrastructure will be shown in the terminal window.
Step 6: Testing Connection
The last step is to confirm that the Ansible control node can connect to the remote hosts.
Use the following code in your control node's terminal to check the connection to the hosts:
Conclusion
Using the tutorial, we were successfully able to install Ansible on the system and also configure an inventory file from an Ansible Control Node.
Last updated