How To Install Ansible on Linux Mint 20
In this tutorial, we will show you how to install Ansible on Linux Mint 20. For those of you who didn’t know, Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It can be used both with Linux-based systems and Windows-based systems. Nowadays Ansible is also used to manage EC2 instances in AWS, Virtual machines, Containers, etc. It does not require any agent on managed hosts, but it only requires an ssh connection.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of an Ansible simple IT automation system on a Linux Mint 20 (Ulyana).
Prerequisites
- A server running one of the following operating systems: Linux Mint 20 (Ulyana).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Ansible on Linux Mint 20 Ulyana
Step 1. Before running the tutorial below, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt install openssh-server sudo apt install software-properties-common
Step 2. Installing Ansible on Linux Mint 20.
By default, Ansible is available on the Linux Mint base repository. Now we will install Ansible on Linux Mint 20 by executing the command below:
sudo apt install ansible
You can verify Ansible installation by checking the installed version:
ansible --version
Step 3. Setup SSH keys.
Ansible controller node uses ssh keys to access the host nodes, now we generate ssh key and copy the public key to the hosts’ authorized keys file:
ssh-keygen
Step 4. Configure Host Nodes for Ansible.
To share the ssh keys between control to managed hosts, run the ssh-copy-id
command example is shown below:
ssh-copy-id meilana@192.168.77.20 ssh-copy-id meilana@192.168.77.21
Next, test if you can access the host nodes from the controller:
ssh meilana@192.168.77.20 ssh meilana@192.168.77.21
Step 5. Create Ansible Inventory File.
Ansible inventory is a file that lists or defines the hosts to be managed via Ansible. /etc/ansible/hosts
is the default Ansible inventory file, To configure the inventory file you can open /etc/ansible/hosts
the file and adjust the configurations:
sudo nano /etc/ansible/hosts
Added the below lines:
node 1 ansible_host=192.168.77.20 node 2 ansible_host=192.168.77.21
Save and close a file, then confirm the servers, and list the content of the inventory file with the command as shown below:
ansible-inventory --list
Step 6. Test Connection Ansible.
Once successfully configured both Ansible controller node and host nodes. Now Ansible should be able to connect to the servers listed in the inventory file using SSH:
ansible all -m ping -u meilana ansible node1 -m ping -u meilana
Check available space on Node1:
ansible node1 -a "df -h" -u meilana
To update all the nodes, run:
ansible all -m apt -a "upgrade=yes update_cache=yes" --become -K
Congratulations! You have successfully installed Ansible. Thanks for using this tutorial for installing the latest version of Ansible simple IT automation on the Linux Mint system. For additional help or useful information, we recommend you check the official Ansible website.