How to Install Ansible (Automation Tool) on Debian 12

In this guide, we will show you how to install Ansible (Automation Tool) on Debian 12 system.

Ansible is a free and open-source automation tool. It is used for configuration management and application deployment. Ansible is available for almost all UNIX like operating systems.

System on which Ansible is installed is known as ‘Control Node’ and systems which are being managed by ansible are known as ‘managed host’.  Ansible does not need any agent on managed hosts as it works on ssh protocol (default port 22).

For the demonstration purpose, I am using following Lab.

  • Ansible Control Node – ( – Debian 12
  • Managed Host 1 – ( – Rocky Linux 9
  • Managed Host 2 – ( – Rocky Linux 9

Minimum System Requirement for Ansible

  • Minimal Debian 12 System
  • Sudo User with root privileges

Let’s deep dive into Ansible Installation steps on Debian 12

1) Install Ansible (Automation Tool) on Debian 12

Ansible Debian package and its dependencies are available in the default Debian 12 package repositories. So, to install ansible, run following commands

$ sudo apt update
$ sudo apt install ansible -y


Once ansible is installed, verify its version by running,

$ ansible --version


Above output confirms that ansible version 2.14.3 is installed.

2) Generate SSH keys and share it between managed hosts

To generate ssh keys, run ‘ssh-keygen’ command


Now exchange ssh keys using ssh-copy-id command,

$ ssh-copy-id
$ ssh-copy-id


On each managed host, configure following for sysops user so that it can run sudo commands without prompting password.

$ echo "sysops ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/sysops

3) Create ansible config file and inventory file

Let’s create project folder with name ‘ansible-demo’,

$ mkdir ansible-demo
$ cd ansible-demo/

Create ansible.cfg file with following content

$ vi ansible.cfg

inventory = ./inventory
host_key_checking = false
remote_user = sysops
ask_pass = False


Save and exit the file.

Create the inventory file,

$ vi inventory


Save & close the file

Now in ‘ansible-demo’ folder we have two files, ansible.cfg and inventory

$ pwd
$ ls -l
total 8
-rw-r--r-- 1 sysops sysops 193 Dec 30 12:24 ansible.cfg
-rw-r--r-- 1 sysops sysops 42 Dec 30 12:25 inventory

4) Test and Verify Ansible Installation

Let’s first verify the managed host connectivity from ansible control node, run following ansible ad-hoc command

$ ansible all -m ping


Perfect, above output confirms ansible is able to perform ping pong test to its managed hosts.

Let’s create a sample playbook to install Apache server on dev node

$ vi demo-nginx.yml

- name: Install NGINX Web Server
  hosts: dev
  - name: install nginx package
      name: nginx
      state: installed
  - name: Start nginx service
      name: nginx
      state: started

save & exit the file

To run the playbook, execute following command

$ ansible-playbook demo-nginx.yml


Verify whether nginx is installed and started on Dev host, run following ansibe ad-hoc commands

$ ansible dev -m shell -a 'rpm -qa | grep -i nginx'
$ ansible dev -m shell -a 'systemctl status nginx'


Great, above output confirms that playbook has been executed successfully on dev host. That’s all from this guide, we hope you have found it informative and useful. Feel free to post your queries and feedback in below comments sections.

Read Also: How to Install Microsoft Teams on Ubuntu/Debian Linux

Leave a Comment

ten + 1 =