DebianDebian Based

How To Install Ansible on Debian 12

Install Ansible on Debian 12

In this tutorial, we will show you how to install Ansible on Debian 12. Ansible is an open-source automation platform that enables you to manage and configure multiple systems from a central location. It uses a simple, human-readable language called YAML to define tasks and playbooks, making it easy to automate complex processes across diverse environments. Whether you’re managing a handful of servers or thousands of nodes, Ansible can streamline your operations and increase efficiency.

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 Ansible Simple IT Automation on a Debian 12 (Bookworm).


  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • 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).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Ansible.
  • A user account with sudo privileges to execute administrative commands.

Install Ansible on Debian 12 Bookworm

Step 1. Keeping your system up-to-date is crucial for security and performance. Use the following commands to update the Debian 12 package index and upgrade all your installed packages to their latest versions:

sudo apt update
sudo apt upgrade

These commands will refresh the package lists and upgrade any outdated packages to their latest versions. It is recommended to reboot your system after performing a system-wide update to ensure all changes take effect.

Step 2. Installing Ansible on Debian 12.

Ansible is available in the default Debian repository, making the installation process straightforward. To install Ansible, run the following command:

sudo apt install ansible

Once the installation is complete, you can verify the installed version of Ansible by running:

ansible --version

This will display the installed Ansible version if the installation was successful.

Step 3. Configuring SSH Access.

For Ansible to communicate with your managed nodes, SSH keys must be generated on the control node and shared with the managed hosts. This step enhances security by using key-based authentication instead of passwords.

Generate SSH keys on the control node:


Then, share the SSH keys with the managed hosts using the ssh-copy-id command:

ssh-copy-id user@managed_host_ip

Step 4. Setting Up Ansible Inventory.

The Ansible inventory file specifies the managed hosts and groups to run playbooks on. Ansible by default uses /etc/ansible/hosts.

Create this file if it does not exist already, and add your managed hosts under relevant groups, for example:



Save this inventory file once all your managed hosts have been added.

Step 5. Run Your First Ad-Hoc Command.

Ad-hoc commands allow you to execute Ansible modules directly from the CLI instead of using playbooks. Let’s test connectivity to managed hosts:

ansible all -m ping -u admin

This will SSH as the admin user on all hosts from the inventory file and execute Ansible’s ping module. You should see pong responses from reachable hosts.

Step 5. Writing Your First Ansible Playbook

Ansible playbooks help you automate multi-step procedures declaratively on remote servers. As an example, here is a playbook to install the Apache web server:

- name: Install Apache 
  hosts: webservers 
  become: true
    - name: Install Apache
        name: apache2 
        state: latest

 Save this as apache.yml and run it with:

ansible-playbook apache.yml

The Apache package will now be installed on the webservers host group from your inventory file.

Congratulations! You have successfully installed Ansible. Thanks for using this tutorial to install the latest version of the Ansible Simple IT Automation on Debian 12 Bookworm. 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!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button