Ansible is a popular open-source automation tool that is used to automate the configuration and deployment of applications. In this article, we will guide you through the process of installing and configuring Ansible on Ubuntu 20.04.
Before we begin, make sure that you have a fresh installation of Ubuntu 20.04 and that the necessary dependencies are installed on your system. You will also need to be logged in as a user with sudo
privileges.
Install the Ansible package
The first step is to install the Ansible package from the default Ubuntu repositories. To do this, run the following command in the terminal:
sudo apt update
sudo apt install ansible
This will install the Ansible package on your system.
Create an Ansible user
After installing Ansible, we need to create a new user that will be used to run Ansible commands. To do this, run the following commands in the terminal:
sudo adduser ansible
sudo usermod -aG sudo ansible
This will create a new user called “ansible” and add it to the sudo
group.
Configure SSH access
Next, we need to configure SSH access for the Ansible user. To do this, log in to the "ansible"
user using the following command:
su - ansible
In the ansible user’s home directory, create a new directory called ".ssh"
using the following command:
mkdir .ssh
Next, generate a new SSH key pair for the ansible user using the following command:
ssh-keygen
Follow the on-screen instructions to generate the SSH key pair. By default, the SSH keys will be saved in the ".ssh"
directory that you created in the previous step.
After generating the SSH key pair, we need to copy the public key to the authorized_keys
file using the following command:
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
This will add the public SSH key to the authorized_keys
file, which allows the Ansible user to log in to the system using the private key.
Configure Ansible
After configuring SSH access for the Ansible user, we need to configure Ansible itself. To do this, open the Ansible configuration file using the following command:
nano /etc/ansible/ansible.cfg
In the configuration file, uncomment the following lines to enable SSH key-based authentication:
private_key_file = /home/ansible/.ssh/id_rsa
host_key_checking = False
Save the file and exit the editor.
By following these steps, you should have successfully installed and configured Ansible on your Ubuntu 20.04 system. You can now use Ansible to automate the configuration and deployment of applications.