Install Ansible on Debian 12 Bookworm: Step-by-Step Guide (apt & pip)
By Luca Berton · Published 2024-01-01 · Category: installation
How to install Ansible on Debian 12 Bookworm. Install via apt repository, pip, configure inventory, test connection. Step-by-step Debian installation guide.

How to install Ansible in Debian version 12?
Today we're going to talk about the easier way to install and maintain Ansible inside Debian using the default "main" repository.
See also: How to install Ansible in Debian 11 - Ansible install
How to install Ansible in Debian
• Included in the "main" default repositoryToday we're talking about How to install Ansible in Debian. The good news is that Ansible is included in the default repository so you could install it simply with your usual package manager "apt". You could expect the latest version of Ansible in the "main" repository.
Step-by-step
Install Ansible in Debian using the apt package manager and the "main" default repository.
code
• install-ansible-debian.sh#!/bin/bash
$ sudo apt-get update
$ sudo apt-get install ansible
$ sudo apt list –installed ansible
execution
$ ssh devops@debian.example.com
$ sudo su
root@debian:/home/devops# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
# cat /etc/debian_version
12.1
# apt-get update
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 http://security.debian.org/debian-security bookworm-security InRelease
Get:3 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
Fetched 52.1 kB in 0s (152 kB/s)
Reading package lists... Done
# apt-cache search ansible
ansible - Configuration management, deployment, and task execution system
ansible-core - Configuration management, deployment, and task execution system
ansible-lint - lint tool for Ansible playbooks
python-ansible-runner-doc - library that interfaces with Ansible (docs)
python3-ansible-runner - library that interfaces with Ansible (Python 3.x)
podman-toolbox - unprivileged development environment using containers
python-network-runner-doc - abstraction of Ansible for interaction with networking devices (docs)
python3-network-runner - abstraction of Ansible for interaction with networking devices (Python 3.x)
python3-ansible-compat - Ansible compatibility goodies
python3-ansible-pygments - pygments lexer and style Ansible snippets
ara-client - ARA Records Ansible - Client
ara-server - ARA Records Ansible - Server
python-ara-doc - ARA Records Ansible - doc
python3-ara - ARA Records Ansible
ansible-mitogen - Fast connection strategy for Ansible
python3-reclass - hierarchical inventory backend for configuration management systems
reclass - hierarchical inventory backend for configuration management systems
reclass-doc - reclass documentation
ssg-applications - SCAP Guides and benchmarks targeting userspace applications
ssg-debderived - SCAP Guides and benchmarks targeting Debian-based OS
ssg-debian - SCAP Guides and benchmarks targeting Debian releases
ssg-nondebian - SCAP Guides and benchmarks targeting other GNU/Linux OS
vim-syntastic - Syntax checking hacks for vim
# apt-cache show ansible
Package: ansible
Version: 7.3.0+dfsg-1
Installed-Size: 204261
Maintainer: Lee Garrett <debian@rocketjump.eu>
Architecture: all
Replaces: ansible-base (<= 2.10.5+dfsg-2)
Depends: ansible-core (>= 2.11.5-1~), python3:any, openssh-client | python3-paramiko (>= 2.6.0), python3-distutils, python3-dnspython, python3-httplib2, python3-jinja2, python3-netaddr, python3-yaml
Recommends: python3-argcomplete, python3-cryptography, python3-jmespath, python3-kerberos, python3-libcloud, python3-selinux, python3-winrm, python3-xmltodict
Suggests: cowsay, sshpass
Breaks: ansible-base (<= 2.10.5+dfsg-2)
Description-en: Configuration management, deployment, and task execution system
Ansible is a radically simple model-driven configuration management,
multi-node deployment, and remote task execution system. Ansible works
over SSH and does not require any software or daemons to be installed
on remote nodes. Extension modules can be written in any language and
are transferred to managed machines automatically.
.
This package contains the ansible collections.
Description-md5: 4f8f35d982ca2a9d6d35c1bb2053b0e1
Homepage: https://www.ansible.com
Tag: admin::automation, admin::configuring, admin::file-distribution,
admin::package-management, implemented-in::python,
interface::commandline, role::program, use::configuring,
works-with::software:running
Section: admin
Priority: optional
Filename: pool/main/a/ansible/ansible_7.3.0+dfsg-1_all.deb
Size: 16253908
MD5sum: 7b1b2cdc2cf66175fffc569031b7be49
SHA256: 14366f29001c3328e5025f862a301dd73f5ce3414a829ed2a5698456b6bee23e
root@debian:/home/devops# apt-get install ansible
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
ansible-core ieee-data libyaml-0-2 python-babel-localedata python3-anyio python3-argcomplete
python3-babel python3-click python3-colorama python3-distutils python3-dnspython python3-h11 python3-h2
python3-hpack python3-httpcore python3-httpx python3-hyperframe python3-jinja2 python3-jmespath
python3-kerberos python3-lib2to3 python3-libcloud python3-lockfile python3-markdown-it
python3-markupsafe python3-mdurl python3-netaddr python3-ntlm-auth python3-packaging
python3-pycryptodome python3-pygments python3-requests-kerberos python3-requests-ntlm
python3-requests-toolbelt python3-resolvelib python3-rfc3986 python3-rich python3-selinux
python3-simplejson python3-sniffio python3-tz python3-winrm python3-xmltodict python3-yaml
Suggested packages:
cowsay sshpass python3-trio python3-aioquic python-jinja2-doc python-lockfile-doc ipython3
python-netaddr-docs python-pygments-doc ttf-bitstream-vera
The following NEW packages will be installed:
ansible ansible-core ieee-data libyaml-0-2 python-babel-localedata python3-anyio python3-argcomplete
python3-babel python3-click python3-colorama python3-distutils python3-dnspython python3-h11 python3-h2
python3-hpack python3-httpcore python3-httpx python3-hyperframe python3-jinja2 python3-jmespath
python3-kerberos python3-lib2to3 python3-libcloud python3-lockfile python3-markdown-it
python3-markupsafe python3-mdurl python3-netaddr python3-ntlm-auth python3-packaging
python3-pycryptodome python3-pygments python3-requests-kerberos python3-requests-ntlm
python3-requests-toolbelt python3-resolvelib python3-rfc3986 python3-rich python3-selinux
python3-simplejson python3-sniffio python3-tz python3-winrm python3-xmltodict python3-yaml
0 upgraded, 45 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/30.1 MB of archives.
After this operation, 290 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Extracting templates from packages: 100%
Selecting previously unselected package python3-markupsafe.
(Reading database ... 33954 files and directories currently installed.)
Preparing to unpack .../00-python3-markupsafe_2.1.2-1+b1_arm64.deb ...
Unpacking python3-markupsafe (2.1.2-1+b1) ...
Selecting previously unselected package python3-jinja2.
Preparing to unpack .../01-python3-jinja2_3.1.2-1_all.deb ...
Unpacking python3-jinja2 (3.1.2-1) ...
Selecting previously unselected package python3-packaging.
Preparing to unpack .../02-python3-packaging_23.0-1_all.deb ...
Unpacking python3-packaging (23.0-1) ...
Selecting previously unselected package python3-resolvelib.
Preparing to unpack .../03-python3-resolvelib_0.9.0-2_all.deb ...
Unpacking python3-resolvelib (0.9.0-2) ...
Selecting previously unselected package libyaml-0-2:arm64.
Preparing to unpack .../04-libyaml-0-2_0.2.5-1_arm64.deb ...
Unpacking libyaml-0-2:arm64 (0.2.5-1) ...
Selecting previously unselected package python3-yaml.
Preparing to unpack .../05-python3-yaml_6.0-3+b2_arm64.deb ...
Unpacking python3-yaml (6.0-3+b2) ...
Selecting previously unselected package python3-pycryptodome.
Preparing to unpack .../06-python3-pycryptodome_3.11.0+dfsg1-4_arm64.deb ...
Unpacking python3-pycryptodome (3.11.0+dfsg1-4) ...
Selecting previously unselected package python3-lib2to3.
Preparing to unpack .../07-python3-lib2to3_3.11.2-3_all.deb ...
Unpacking python3-lib2to3 (3.11.2-3) ...
Selecting previously unselected package python3-distutils.
Preparing to unpack .../08-python3-distutils_3.11.2-3_all.deb ...
Unpacking python3-distutils (3.11.2-3) ...
Selecting previously unselected package python3-dnspython.
Preparing to unpack .../09-python3-dnspython_2.3.0-1_all.deb ...
Unpacking python3-dnspython (2.3.0-1) ...
Selecting previously unselected package ieee-data.
Preparing to unpack .../10-ieee-data_20220827.1_all.deb ...
Unpacking ieee-data (20220827.1) ...
Selecting previously unselected package python3-netaddr.
Preparing to unpack .../11-python3-netaddr_0.8.0-2_all.deb ...
Unpacking python3-netaddr (0.8.0-2) ...
Selecting previously unselected package ansible-core.
Preparing to unpack .../12-ansible-core_2.14.3-1_all.deb ...
Unpacking ansible-core (2.14.3-1) ...
Selecting previously unselected package ansible.
Preparing to unpack .../13-ansible_7.3.0+dfsg-1_all.deb ...
Unpacking ansible (7.3.0+dfsg-1) ...
Selecting previously unselected package python-babel-localedata.
Preparing to unpack .../14-python-babel-localedata_2.10.3-1_all.deb ...
Unpacking python-babel-localedata (2.10.3-1) ...
Selecting previously unselected package python3-sniffio.
Preparing to unpack .../15-python3-sniffio_1.2.0-1_all.deb ...
Unpacking python3-sniffio (1.2.0-1) ...
Selecting previously unselected package python3-anyio.
Preparing to unpack .../16-python3-anyio_3.6.2-1_all.deb ...
Unpacking python3-anyio (3.6.2-1) ...
Selecting previously unselected package python3-argcomplete.
Preparing to unpack .../17-python3-argcomplete_2.0.0-1_all.deb ...
Unpacking python3-argcomplete (2.0.0-1) ...
Selecting previously unselected package python3-tz.
Preparing to unpack .../18-python3-tz_2022.7.1-4_all.deb ...
Unpacking python3-tz (2022.7.1-4) ...
Selecting previously unselected package python3-babel.
Preparing to unpack .../19-python3-babel_2.10.3-1_all.deb ...
Unpacking python3-babel (2.10.3-1) ...
Selecting previously unselected package python3-colorama.
Preparing to unpack .../20-python3-colorama_0.4.6-2_all.deb ...
Unpacking python3-colorama (0.4.6-2) ...
Selecting previously unselected package python3-click.
Preparing to unpack .../21-python3-click_8.1.3-2_all.deb ...
Unpacking python3-click (8.1.3-2) ...
Selecting previously unselected package python3-h11.
Preparing to unpack .../22-python3-h11_0.14.0-1_all.deb ...
Unpacking python3-h11 (0.14.0-1) ...
Selecting previously unselected package python3-hpack.
Preparing to unpack .../23-python3-hpack_4.0.0-2_all.deb ...
Unpacking python3-hpack (4.0.0-2) ...
Selecting previously unselected package python3-hyperframe.
Preparing to unpack .../24-python3-hyperframe_6.0.0-1_all.deb ...
Unpacking python3-hyperframe (6.0.0-1) ...
Selecting previously unselected package python3-h2.
Preparing to unpack .../25-python3-h2_4.1.0-4_all.deb ...
Unpacking python3-h2 (4.1.0-4) ...
Selecting previously unselected package python3-httpcore.
Preparing to unpack .../26-python3-httpcore_0.16.3-1_all.deb ...
Unpacking python3-httpcore (0.16.3-1) ...
Selecting previously unselected package python3-pygments.
Preparing to unpack .../27-python3-pygments_2.14.0+dfsg-1_all.deb ...
Unpacking python3-pygments (2.14.0+dfsg-1) ...
Selecting previously unselected package python3-mdurl.
Preparing to unpack .../28-python3-mdurl_0.1.2-1_all.deb ...
Unpacking python3-mdurl (0.1.2-1) ...
Selecting previously unselected package python3-markdown-it.
Preparing to unpack .../29-python3-markdown-it_2.1.0-5_all.deb ...
Unpacking python3-markdown-it (2.1.0-5) ...
Selecting previously unselected package python3-rich.
Preparing to unpack .../30-python3-rich_13.3.1-1_all.deb ...
Unpacking python3-rich (13.3.1-1) ...
Selecting previously unselected package python3-rfc3986.
Preparing to unpack .../31-python3-rfc3986_1.5.0-2_all.deb ...
Unpacking python3-rfc3986 (1.5.0-2) ...
Selecting previously unselected package python3-httpx.
Preparing to unpack .../32-python3-httpx_0.23.3-1_all.deb ...
Unpacking python3-httpx (0.23.3-1) ...
Selecting previously unselected package python3-jmespath.
Preparing to unpack .../33-python3-jmespath_1.0.1-1_all.deb ...
Unpacking python3-jmespath (1.0.1-1) ...
Selecting previously unselected package python3-kerberos.
Preparing to unpack .../34-python3-kerberos_1.1.14-3.1+b7_arm64.deb ...
Unpacking python3-kerberos (1.1.14-3.1+b7) ...
Selecting previously unselected package python3-lockfile.
Preparing to unpack .../35-python3-lockfile_1%3a0.12.2-2.2_all.deb ...
Unpacking python3-lockfile (1:0.12.2-2.2) ...
Selecting previously unselected package python3-simplejson.
Preparing to unpack .../36-python3-simplejson_3.18.3-1_arm64.deb ...
Unpacking python3-simplejson (3.18.3-1) ...
Selecting previously unselected package python3-libcloud.
Preparing to unpack .../37-python3-libcloud_3.4.1-5_all.deb ...
Unpacking python3-libcloud (3.4.1-5) ...
Selecting previously unselected package python3-ntlm-auth.
Preparing to unpack .../38-python3-ntlm-auth_1.4.0-2_all.deb ...
Unpacking python3-ntlm-auth (1.4.0-2) ...
Selecting previously unselected package python3-requests-kerberos.
Preparing to unpack .../39-python3-requests-kerberos_0.12.0-2_all.deb ...
Unpacking python3-requests-kerberos (0.12.0-2) ...
Selecting previously unselected package python3-requests-ntlm.
Preparing to unpack .../40-python3-requests-ntlm_1.1.0-3_all.deb ...
Unpacking python3-requests-ntlm (1.1.0-3) ...
Selecting previously unselected package python3-requests-toolbelt.
Preparing to unpack .../41-python3-requests-toolbelt_0.10.1-1_all.deb ...
Unpacking python3-requests-toolbelt (0.10.1-1) ...
Selecting previously unselected package python3-selinux.
Preparing to unpack .../42-python3-selinux_3.4-1+b6_arm64.deb ...
Unpacking python3-selinux (3.4-1+b6) ...
Selecting previously unselected package python3-xmltodict.
Preparing to unpack .../43-python3-xmltodict_0.13.0-1_all.deb ...
Unpacking python3-xmltodict (0.13.0-1) ...
Selecting previously unselected package python3-winrm.
Preparing to unpack .../44-python3-winrm_0.3.0-4_all.deb ...
Unpacking python3-winrm (0.3.0-4) ...
Setting up python3-sniffio (1.2.0-1) ...
Setting up python3-lockfile (1:0.12.2-2.2) ...
Setting up python3-requests-toolbelt (0.10.1-1) ...
Setting up python3-anyio (3.6.2-1) ...
Setting up python3-hyperframe (6.0.0-1) ...
Setting up python3-hpack (4.0.0-2) ...
Setting up python3-colorama (0.4.6-2) ...
Setting up libyaml-0-2:arm64 (0.2.5-1) ...
Setting up python3-ntlm-auth (1.4.0-2) ...
Setting up python3-pycryptodome (3.11.0+dfsg1-4) ...
Setting up python3-resolvelib (0.9.0-2) ...
Setting up python3-kerberos (1.1.14-3.1+b7) ...
Setting up python3-yaml (6.0-3+b2) ...
Setting up python3-click (8.1.3-2) ...
Setting up python3-markupsafe (2.1.2-1+b1) ...
Setting up python3-tz (2022.7.1-4) ...
Setting up python-babel-localedata (2.10.3-1) ...
Setting up python3-simplejson (3.18.3-1) ...
Setting up python3-xmltodict (0.13.0-1) ...
Setting up python3-jinja2 (3.1.2-1) ...
Setting up python3-pygments (2.14.0+dfsg-1) ...
Setting up python3-packaging (23.0-1) ...
Setting up python3-rfc3986 (1.5.0-2) ...
Setting up python3-jmespath (1.0.1-1) ...
Setting up python3-mdurl (0.1.2-1) ...
Setting up python3-h11 (0.14.0-1) ...
Setting up python3-markdown-it (2.1.0-5) ...
Setting up python3-requests-kerberos (0.12.0-2) ...
Setting up ieee-data (20220827.1) ...
Setting up python3-dnspython (2.3.0-1) ...
Setting up python3-selinux (3.4-1+b6) ...
Setting up python3-h2 (4.1.0-4) ...
Setting up python3-argcomplete (2.0.0-1) ...
Setting up python3-lib2to3 (3.11.2-3) ...
Setting up python3-distutils (3.11.2-3) ...
Setting up python3-httpcore (0.16.3-1) ...
Setting up python3-requests-ntlm (1.1.0-3) ...
Setting up python3-babel (2.10.3-1) ...
update-alternatives: using /usr/bin/pybabel-python3 to provide /usr/bin/pybabel (pybabel) in auto mode
Setting up python3-rich (13.3.1-1) ...
Setting up python3-libcloud (3.4.1-5) ...
Setting up python3-httpx (0.23.3-1) ...
Setting up python3-netaddr (0.8.0-2) ...
Setting up python3-winrm (0.3.0-4) ...
Setting up ansible-core (2.14.3-1) ...
Setting up ansible (7.3.0+dfsg-1) ...
Processing triggers for man-db (2.11.2-2) ...
Processing triggers for libc-bin (2.36-9+deb12u1) ...
root@debian:/home/devops# ansible --version
ansible [core 2.14.3]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
root@debian:/home/devops# apt list | grep ansible
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
ansible-core/stable,now 2.14.3-1 all [installed,automatic]
ansible-lint/stable 6.13.1-1 all
ansible-mitogen/stable 0.3.3-9 all
ansible/stable,now 7.3.0+dfsg-1 all [installed]
python-ansible-runner-doc/stable 2.3.1-2 all
python3-ansible-compat/stable 3.0.1-1 all
python3-ansible-pygments/stable 0.1.1-5 all
python3-ansible-runner/stable 2.3.1-2 all
root@debian:/home/devops# dpkg -l | grep ansible
ii ansible 7.3.0+dfsg-1 all Configuration management, deployment, and task execution system
ii ansible-core 2.14.3-1 all Configuration management, deployment, and task execution system Configuration management, deployment, and task execution system
root@debian:/home/devops#
before execution
$ ssh devops@debian.example.com
$ sudo su
root@debian:/home/devops# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@debian:/home/devops# cat /etc/debian_version
12.1
root@debian:/home/devops# apt list ansible --installed
Listing... Done
root@debian:/home/devops#
after execution
root@debian:/home/devops# apt list ansible --installed
Listing... Done
ansible/stable,now 7.3.0+dfsg-1 all [installed]
root@debian:/home/devops# dpkg -l | grep ansible
ii ansible 7.3.0+dfsg-1 all Configuration management, deployment, and task execution system
ii ansible-core 2.14.3-1 all Configuration management, deployment, and task execution system
See also: How to Run Linux Fedora Workstation 39 on an Apple Mac
Conclusion
Now you know how to install the latest version of Ansible in Debian using the "main" repository.
Related Articles
• Jinja2 filters in Ansible templates • Ansible Inventory GuideSee also: Run RHEL 9.2 on Mac Using VMware Fusion: A Step-by-Step Guide
See also
• How to install Ansible on Raspberry Pi OS (Bookworm)Verifying Your Installation
After installing Ansible, verify everything works:
# Check Ansible version
ansible --version
# Test local connection
ansible localhost -m ansible.builtin.ping
# List installed collections
ansible-galaxy collection list
Installing Additional Collections
Debian 12's apt package provides ansible-core. Install additional collections as needed:
# Install common collections
ansible-galaxy collection install community.general
ansible-galaxy collection install ansible.posix
ansible-galaxy collection install community.docker
Setting Up a Virtual Environment (Recommended)
For production use, isolate Ansible in a Python virtual environment:
# Install venv
sudo apt install -y python3-venv
# Create virtual environment
python3 -m venv ~/ansible-venv
# Activate and install
source ~/ansible-venv/bin/activate
pip install ansible ansible-lint
# Verify
ansible --version
Automate Ansible Installation with a Playbook
---
- name: Install Ansible on Debian 12
hosts: debian12_nodes
become: true
tasks:
- name: Install prerequisites
ansible.builtin.apt:
name:
- python3
- python3-pip
- python3-venv
- sshpass
state: present
update_cache: true
- name: Install Ansible via pip in venv
ansible.builtin.pip:
name:
- ansible
- ansible-lint
virtualenv: /opt/ansible-venv
virtualenv_command: python3 -m venv
FAQ
Which Python version does Debian 12 include?
Debian 12 (Bookworm) ships with Python 3.11.
Should I install ansible or ansible-core on Debian 12?
Use ansible (full package) for most use cases — it includes commonly used collections. Use ansible-core only if you want minimal installation and will manage collections manually.
Can I use the Debian apt package for production?
Yes, but the apt version may lag behind pip. For the latest features, use pip install ansible in a virtual environment.
How do I upgrade Ansible on Debian 12?
With apt: sudo apt update && sudo apt upgrade ansible. With pip: pip install --upgrade ansible.
Category: installation
Watch the video: Install Ansible on Debian 12 Bookworm: Step-by-Step Guide (apt & pip) — Video Tutorial