# Debian 12 upgrade python3-docker for docker\_swarm\_module

**URL:** <https://forum.ansible.com/t/debian-12-upgrade-python3-docker-for-docker-swarm-module/43989>\
**Category:** Get Help\
**Tags:** docker-swarm\
**Created:** [July 22, 2025, 3:17pm UTC](https://forum.ansible.com/t/debian-12-upgrade-python3-docker-for-docker-swarm-module/43989 "2025-07-22T15:17:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![romgo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/romgo/32/5202_2.png) [@romgo](https://forum.ansible.com/u/romgo)\
**Post date:** [July 22, 2025, 3:17pm UTC](https://forum.ansible.com/t/debian-12-upgrade-python3-docker-for-docker-swarm-module/43989/1 "2025-07-22T15:17:02Z")

</div>

Hello,

I am writing an ansible role to manage & create a docker swarm cluster. The target servers are debian 12.

Using the reference page : [community.docker.docker\_swarm module – Manage Swarm cluster — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections/community/docker/docker_swarm_module.html)

I need to set data\_path\_port to a specific value not the default one.

This is the code :

```auto
- name: Initialize swarm
  community.docker.docker_swarm:
    state: present
    data_path_port: "{{ docker_swarm_data_port }}"
  register: swarm_status
  when: inventory_hostname in groups['swarm-mgmt'][0]

```

it fails stating :

```auto
fatal: [server]: FAILED! => {"changed": false, "msg": "Docker SDK for Python version is 5.0.3 (tstsrv01's Python /usr/bin/python3.11). Minimum version required is 6.0.0 to set data_path_port option. Use `pip install --upgrade docker` to upgrade."}`

```

On debian 12 we have this version available :

```auto
root@server01:~# apt policy python3-docker
python3-docker:
  Installé : 5.0.3-1
  Candidat : 5.0.3-1
 Table de version :
 *** 5.0.3-1 500
        500 http://httpredir.debian.org/debian bookworm/main amd64 Packages
        100 /var/lib/dpkg/status

```

The thing is by default we cannot play with pip on system lelve, we need to use python venv, but in this case how can this works with ansible ?

Thank you for your help

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [July 22, 2025, 3:52pm UTC](https://forum.ansible.com/t/debian-12-upgrade-python3-docker-for-docker-swarm-module/43989/2 "2025-07-22T15:52:23Z")

</div>

Can you install the Docker SDK for Python in a virtual environment?

This probably won’t help but Debian Trixie is due out in a few weeks and has [python3-docker (7.1.0-2)](https://packages.debian.org/trixie/python3-docker).

---

<div class="post-metadata">

**Author:** ![romgo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/romgo/32/5202_2.png) [@romgo](https://forum.ansible.com/u/romgo)\
**Post date:** [July 22, 2025, 3:55pm UTC](https://forum.ansible.com/t/debian-12-upgrade-python3-docker-for-docker-swarm-module/43989/3 "2025-07-22T15:55:18Z")

</div>

> [@chris](#):
>
> probably won’t help but Debian Trixie

So I was able to avoid this issue by creating a venv with required lib version & modify the ansible\_python\_interpretervariable before docker swarm module getting started.

```auto
- name: Install python3-venv
  ansible.builtin.package:
    name: python3-venv
    state: present

- name: Create python venv and install packages
  ansible.builtin.pip:
    virtualenv: "{{ docker_swarm_venv_path }}"
    virtualenv_command: "python3 -m venv"
    name:
      - docker

- name: Set python interpreter to use venv
  ansible.builtin.set_fact:
    ansible_python_interpreter: "{{ docker_swarm_venv_path }}/bin/python"

```

Don’t think this is very elegant, but it just works !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 21, 2025, 3:56pm UTC](https://forum.ansible.com/t/debian-12-upgrade-python3-docker-for-docker-swarm-module/43989/4 "2025-08-21T15:56:19Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
