How To Install Ansible on Debian 11

Install Ansible on Debian 11

In this tutorial, we will show you how to install Ansible on Debian 11. For those of you who didn’t know, Ansible is the simplest way to automate apps and IT infrastructure. Ansible uses port 22 (SSH) to connect to a remote machine and make the necessary changes. It is a cross-platform tool designed to handle system configurations while working with Linux, macOS, and Windows operating systems.

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 through the step-by-step installation of the Ansible on a Debian 11 (Bullseye).

Install Ansible on Debian 11 Bullseye

Step 1. Before we install any software, 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 upgrade
sudo apt install gnupg2 curl wget

Step 2. Installing Ansible on Debian 11.

  • Install Ansible using Debian default repositories.

By default, Ansible is available in Debian’s default repositories, Now we run the following command to install it:

sudo apt install ansible
  • Install Ansible from the official repository.

Now we add the Ansible repository to your system:

nano /etc/apt/sources.list

Add the following line:

deb http://ppa.launchpad.net/ansible/ansible/ubuntu focal main

Next, add the Ansible GPG key using the following command:

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367

Once done, Update the system package and install Ansible using the following command below:

sudo apt update
sudo apt install ansible

Verify the Ansible installation using the following command:

ansible --version
  • Install Ansible using Python.

A better solution over installing Ansible from the Debian package repository is to install it using Pip or Pip3:

sudo install python3 python3-pip

Once the installation is complete, use the pip command to install Ansible:

pip install ansible

Step 3. Configure Ansible Controller Hosts.

We create an inventory file to define your remote hosts IP address, username, password, and SSH port:

nano ~/.hosts

Add the following lines:

[servers]
server1 ansible_host=192.168.77.20 ansible_user=root ansible_ssh_pass=password ansible_ssh_port=22
server2 ansible_host=192.168.77.21 ansible_user=root ansible_ssh_pass=password ansible_ssh_port=22

We will assume that our Debian managed node server’s IP addresses are 192.168.77.20 and 192.168.77.21.

To allow the Ansible controller node to communicate with managed nodes, we must confirm that managed nodes are accessible on port 22 which is an SSH port. Execute the below command to confirm the connectivity one by one on all three managed nodes from the controller:

ssh [email protected]
ssh [email protected]

You will be prompted for the password of the root user of all the nodes. Ansible works very smoothly if you have password-less authentication configured between the Ansible controller and managed nodes. With different parameters in the Ansible command, password authentication can work too.

Let’s try to connect to managed nodes from the Ansible controller now:

ansible -m ping servers

Congratulations! You have successfully installed Ansible. Thanks for using this tutorial for installing the latest version of Ansible on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Ansible website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!