No description
Find a file
semantic-release-bot a4c0d42544 chore(release): 1.22.1 [skip ci]
## [1.22.1](https://github.com/de-it-krachten/ansible-role-python/compare/v1.22.0...v1.22.1) (2026-04-08)

### Bug Fixes

* Add support for python 3.10 on Ubuntu 24.04 ([21d60c4](21d60c4e75))
2026-04-08 16:05:45 +00:00
.github/workflows Update CI 2026-04-03 23:59:58 +02:00
defaults fix: Add support for python 3.10 on Ubuntu 24.04 2026-04-05 14:29:19 +02:00
meta Update CI 2026-03-14 19:54:47 +01:00
molecule/default Update CI 2026-04-03 23:59:58 +02:00
tasks feat: Add support for Python from PPA/deadsnakes on Ubuntu 2026-04-04 00:58:23 +02:00
.ansible-lint Update CI 2026-04-03 23:59:58 +02:00
.cicd Update CI 2026-04-03 23:59:58 +02:00
.cicd.overwrite Update CI 2026-03-14 19:54:47 +01:00
.collections Move community.general version out of this role 2025-12-06 21:03:32 +01:00
.gitignore fix: Delete unwanted '.ansible' files making 'ansible-galaxy' fail 2025-08-04 22:01:00 +02:00
.releaserc.yml feat: Add support for Fedora43 2025-12-05 23:10:35 +01:00
.roles feat: Move to FQCN 2022-10-11 17:36:01 +02:00
.yamllint feat: Update supported platforms & CI 2024-12-29 11:44:51 +01:00
CHANGELOG.md chore(release): 1.22.1 [skip ci] 2026-04-08 16:05:45 +00:00
README.md feat: Add support for Python from PPA/deadsnakes on Ubuntu 2026-04-04 00:58:23 +02:00

CI

ansible-role-python

Installs python from repository

Dependencies

Roles

None

Collections

  • community.general

Platforms

Supported platforms

  • Red Hat Enterprise Linux 81
  • Red Hat Enterprise Linux 91
  • Red Hat Enterprise Linux 101
  • RockyLinux 8
  • RockyLinux 9
  • RockyLinux 10
  • OracleLinux 8
  • OracleLinux 9
  • OracleLinux 10
  • AlmaLinux 8
  • AlmaLinux 9
  • AlmaLinux 10
  • Debian 11 (Bullseye)
  • Debian 12 (Bookworm)
  • Debian 13 (Trixie)
  • Ubuntu 22.04 LTS
  • Ubuntu 24.04 LTS
  • Ubuntu 26.04 LTS
  • Fedora 42
  • Fedora 43
  • Alpine 31

Note: 1 : no automated testing is performed on these platforms

Role Variables

defaults/main.yml


# Python versions to install
python2: false
python3: true

# Default root-directory for virtual environments
python_virtualenv_root: "{{ ansible_env['HOME'] }}/.virtualenv"

# Install default python packages
python_package_install: true

# Install additional python packages (might be required when compilation is required)
python_package_install_optional: false

# Allow python installed from deadsnakes (Ubuntu only)
python_deadsnakes: false

# List of pypi packages that should exist in the virtualenv
python_virtualenv_packages:
  - pip
  - setuptools
  - wheel

# Upgrade main package for new virtual environments
python_virtualenv_upgrade: true

# Execute code for venv creation only
python_virtualenv_only: false

# Create empty venv
python_virtualenv_empty: false

# Use list of trusted hosts as defined under python_trusted_hosts
python_trust_hosts: false

# List of trusted hosts
python_trusted_hosts: >
  --trusted-host pypi.org
  --trusted-host files.pythonhosted.org
  --trusted-host pypi.python.org

# Use to become when setting up virtual environments
python_venv_become: root

# Custom template for /etc/pip.conf file
# python_custom_pip_conf: templates/pip.conf.j2

# Define pip executable
pip_executable: pip

# List of additional pip clients
pip_clients:
  - pip
  - pip3

# Upgrade pip (site-packages) when out-dated
pip_site_upgrade: false

# Upgrade pip (venv) when out-dated
pip_upgrade: false

# virtual environments to set-up
python_virtualenvs: []

# virtual env command
python_virtualenv_command: /usr/bin/virtualenv

# Python (from source)
python_from_source: false
python_version: 3.8.12
python_version_minor: "{{ python_version | regex_replace('^(\\d\\.\\d)(.*)', '\\1') }}"

python_binary: python{{ python_version_minor }}
python_binary_full: /usr/local/bin/{{ python_binary }}

python_url: https://www.python.org/ftp/python/{{ python_version }}/Python-{{ python_version }}.tgz

defaults/Debian-11.yml


# Supported versions
python_default: '3.9'
python_supported:
  - '3.9'

defaults/Debian-12.yml


# Supported versions
python_default: '3.11'
python_supported:
  - '3.11'

defaults/Debian-13.yml


# Supported versions
python_default: '3.13'
python_supported:
  - '3.13'

defaults/family-Alpine.yml


# Python2
python2: false
python2_command: /usr/bin/python2
python2_virtualenv: /usr/bin/virtualenv
python2_packages:
  - python2
python2_packages_optional: []

# Python3
python3: true
python3_command: /usr/bin/python3
python3_virtualenv: /usr/bin/virtualenv
python3_packages:
  - python3
  - py3-pip
  - py3-virtualenv
python3_packages_optional:
  - build-base
  - gcc
  - g++
  - libffi-dev
  - musl-dev
  - openssl-dev
  - python3-dev

# Supported versions
python_default: '3.11'
python_supported:
  - '3.11'

defaults/family-Debian.yml


# Python2
python2: false
python2_command: /usr/bin/python2
python2_virtualenv: /usr/bin/virtualenv
python2_packages:
  - python
  - python-pip
  - python-virtualenv
python2_packages_optional: []

# Python3
python3: true
python3_command: /usr/bin/python3
python3_virtualenv: /usr/bin/virtualenv
python3_packages:
  - python3
  - python3-pip
  - python3-virtualenv
  - python3-venv
  - python3-setuptools
  - virtualenv
  - python3-virtualenv
python3_packages_optional:
  - gcc
  - libffi-dev
  - python3-dev

python3_packages_src:
  - build-essential
  - zlib1g-dev
  - libncurses5-dev
  - libgdbm-dev
  - libnss3-dev
  - libssl-dev
  - libsqlite3-dev
  - libreadline-dev
  - libffi-dev
  - curl
  - libbz2-dev

# Python 3.8
python38: false
python38_command: /usr/bin/python3.8
python38_virtualenv: /usr/bin/virtualenv
python38_packages:
  - python3.8
  - python3.8-venv
python38_packages_optional:
  - python3.8-dev

# Python 3.9
python39: false
python39_command: /usr/bin/python3.9
python39_virtualenv: /usr/bin/virtualenv
python39_packages:
  - python3.9
  - python3.9-venv
python39_packages_optional:
  - python3.9-dev

# Python 3.10
python310: false
python310_command: /usr/bin/python3.10
python310_virtualenv: /usr/bin/virtualenv
python310_packages:
  - python3.10
  - python3.10-venv
python310_packages_optional:
  - python3.10-dev

# Python 3.11
python311: false
python311_command: /usr/bin/python3.11
python311_virtualenv: /usr/bin/virtualenv
python311_packages:
  - python3.11
  - python3.11-venv
python311_packages_optional:
  - python3.11-dev

# Python 3.12
python312: false
python312_command: /usr/bin/python3.12
python312_virtualenv: /usr/bin/virtualenv
python312_packages:
  - python3.12
  - python3.12-venv
python312_packages_optional:
  - python3.12-dev

# Python 3.13
python313: false
python313_command: /usr/bin/python3.13
python313_virtualenv: /usr/bin/virtualenv
python313_packages:
  - python3.13
  - python3.13-venv
python313_packages_optional:
  - python3.13-dev

# Python 3.14
python314: false
python314_command: /usr/bin/python3.14
python314_virtualenv: /usr/bin/virtualenv
python314_packages:
  - python3.14
  - python3.14-venv
python314_packages_optional:
  - python3.14-dev

defaults/family-RedHat-10.yml


# Supported versions
python_default: '3.12'
python_supported:
  - '3.12'

# Python3
python3: true
python3_command: /usr/bin/python3
python3_virtualenv: /usr/bin/virtualenv
python3_packages:
  - python3
  - python3-libs
  - python3-pip
  - python3-virtualenv
  - python3-setuptools
  - libselinux-python3
python3_packages_optional:
  - gcc
  - python3-devel
  - glibc-devel
  - openssl-devel
  - libffi-devel

defaults/family-RedHat-8.yml


# Supported versions
python_default: '3.6'
python_supported:
  - '3.6'
  - '3.8'
  - '3.9'
  - '3.11'
  - '3.12'

# Python3
python3: true
python3_command: /usr/bin/python3
python3_virtualenv: /usr/bin/virtualenv-3.6
python3_packages:
  - python36
  - python3-libs
  - python3-pip
  - python3-virtualenv
  - python3-setuptools
  - libselinux-python3
python3_packages_optional:
  - gcc
  - python36-devel
  - glibc-devel
  - openssl-devel
  - libffi-devel

defaults/family-RedHat-9.yml


# Supported versions
python_default: '3.9'
python_supported:
  - '3.9'
  - '3.11'
  - '3.12'

# Python3
python3: true
python3_command: /usr/bin/python3
python3_virtualenv: /usr/bin/virtualenv
python3_packages:
  - python3
  - python3-libs
  - python3-pip
  - python3-virtualenv
  - python3-setuptools
  - libselinux-python3
python3_packages_optional:
  - gcc
  - python3-devel
  - glibc-devel
  - openssl-devel
  - libffi-devel

defaults/family-RedHat.yml


# Python 3.8
python38: false
python38_command: /usr/bin/python3.8
python38_virtualenv: /usr/bin/virtualenv
python38_packages:
  - python38
  - python38-libs
  - python38-pip
  - python3-virtualenv
python38_packages_optional:
  - python38-devel

# Python 3.9
python39: false
python39_command: /usr/bin/python3.9
python39_virtualenv: /usr/bin/virtualenv
python39_packages:
  - python39
  - python39-libs
  - python39-pip
  - python3-virtualenv
python39_packages_optional:
  - python39-devel

# Python 3.10
python310: false
python310_command: /usr/bin/python3.10
python310_virtualenv: /usr/bin/virtualenv
python310_packages:
  - python3.10
  - python3.10-libs
  - python3.10-pip
  - python3.10-setuptools
  - python3-virtualenv
python310_packages_optional:
  - python3.10-devel

# Python 3.11
python311: false
python311_command: /usr/bin/python3.11
python311_virtualenv: /usr/bin/virtualenv
python311_packages:
  - python3.11
  - python3.11-libs
  - python3.11-pip
  - python3.11-setuptools
  - python3-virtualenv
python311_packages_optional:
  - python3.11-devel

# Python 3.12
python312: false
python312_command: /usr/bin/python3.12
python312_virtualenv: /usr/bin/virtualenv
python312_packages:
  - python3.12
  - python3.12-libs
  - python3.12-pip
  - python3.12-setuptools
  - python3-virtualenv
python312_packages_optional:
  - python3.12-devel

# Python 3.13
python313: false
python313_command: /usr/bin/python3.13
python313_virtualenv: /usr/bin/virtualenv
python313_packages:
  - python3.13
  - python3.13-libs
  - python3.13-pip
  - python3.13-setuptools
  - python3-virtualenv
python313_packages_optional:
  - python3.13-devel

# Python 3.14
python314: false
python314_command: /usr/bin/python3.14
python314_virtualenv: /usr/bin/virtualenv
python314_packages:
  - python3.14
  - python3.14-libs
  - python3.14-pip
  - python3.14-setuptools
  - python3-virtualenv
python314_packages_optional:
  - python3.14-devel

# Python from source
python3_packages_src:
  - '@Development Tools'
  - gcc
  - openssl-devel
  - bzip2-devel
  - libffi-devel
  - xz-devel

defaults/family-Suse-15.yml


# Supported versions
python_default: '3.6'
python_supported:
  - '3.6'
  - '3.9'
      # - '3.10'
  - '3.11'
  - '3.12'

defaults/family-Suse-16.yml


# Supported versions
python_default: '3.13'
python_supported:
  - '3.13'

defaults/family-Suse.yml


# Python2
python2: false
python2_command: /usr/bin/python2
python2_virtualenv: /usr/bin/virtualenv-2.7
python2_packages:
  - python
  - python-libs
  - python-pip
  - python-virtualenv
  - libselinux-python
python2_packages_optional:
  - gcc
  - glibc-devel
  - python-devel
  - openssl-devel
  - libffi-devel

# Python3
python3: true
python3_command: /usr/bin/python3
python3_virtualenv: /usr/bin/virtualenv
python3_packages:
  - python3
  - python3-base
  - python3-setuptools
  - python3-pip
  - python3-virtualenv
  - python3-devel
python3_packages_optional:
  - gcc
  - python3-devel
  - glibc-devel
  - openssl-devel
  - libffi-devel

# Python from source
python3_packages_src:
  - '@Development Tools'
  - gcc
  - openssl-devel
  - bzip2-devel
  - libffi-devel
  - xz-devel

# Python 3.9
python39: false
python39_command: /usr/bin/python3.9
python39_virtualenv: '/usr/bin/python3.9 -m venv'
python39_packages:
  - python39
#  - python39-pip
  - python3-virtualenv
python39_packages_optional:
  - python39-devel

# Python 3.10
python310: false
python310_command: /usr/bin/python3.10
python310_virtualenv: '/usr/bin/python3.10 -m venv'
python310_packages:
  - python310
#  - python310-pip
  - python310-setuptools
  - python3-virtualenv
python310_packages_optional:
  - python310-devel

# Python 3.11
python311: false
python311_command: /usr/bin/python3.11
python311_virtualenv: '/usr/bin/python3.11 -m venv'
python311_packages:
  - python311
  - python311-pip
  - python311-setuptools
  - python3-virtualenv
python311_packages_optional:
  - python311-devel

# Python 3.12
python312: false
python312_command: /usr/bin/python3.12
python312_virtualenv: '/usr/bin/python3.12 -m venv'
python312_packages:
  - python312
  - python312-pip
  - python312-setuptools
  - python3-virtualenv
python312_packages_optional:
  - python312-devel

# Python 3.13
python313: false
python313_command: /usr/bin/python3.13
python313_virtualenv: '/usr/bin/python3.13 -m venv'
python313_packages:
  - python313
  - python313-pip
  - python313-setuptools
  - python3-virtualenv
python313_packages_optional:
  - python313-devel

# Python 3.14
python314: false
python314_command: /usr/bin/python3.14
python314_virtualenv: '/usr/bin/python3.14 -m venv'
python314_packages:
  - python314
  - python314-pip
  - python314-setuptools
  - python3-virtualenv
python314_packages_optional:
  - python314-devel

defaults/Fedora-40.yml


# Supported versions
python_default: '3.12'
python_supported:
  - '3.12'

defaults/Fedora-41.yml


# Supported versions
python_default: '3.13'
python_supported:
  - '3.13'

defaults/Fedora-43.yml


# Supported versions
python_default: '3.14'
python_supported:
  - '3.14'

defaults/Fedora.yml


# Python2
python2: false
python2_command: /usr/bin/python2
python2_virtualenv: /usr/bin/virtualenv
python2_packages:
  - python2
  - python2-libs
  - python2-devel
  - python2-pip
  - python2-virtualenv
  - libselinux-python
python2_packages_optional:
  - gcc
  - glibc-devel
  - openssl-devel

# Python3
python3: true
python3_command: /usr/bin/python3
python3_virtualenv: /usr/bin/virtualenv
python3_packages:
  - python3
  - python3-libs
  - python3-pip
  - python3-virtualenv
  - python3-libselinux
python3_packages_optional:
  - gcc
  - python3-devel
  - glibc-devel
  - openssl-devel
  - libffi-devel

# Python 3.8
python38: false
python38_command: /usr/bin/python3.8
python38_virtualenv: /usr/bin/virtualenv
python38_packages:
  - python3.8
python38_packages_optional: []

# Python 3.9
python39: false
python39_command: /usr/bin/python3.9
python39_virtualenv: /usr/bin/virtualenv
python39_packages:
  - python3.9
python39_packages_optional: []

defaults/Ubuntu-20.yml


# Supported versions
python_default: '3.8'
python_supported:
  - '3.6'
  - '3.7'
  - '3.8'
  - '3.9'

defaults/Ubuntu-22.yml


# Supported versions
python_default: '3.10'
python_supported:
  - '3.10'
  - '3.11'
python_supported_deadsnakes:
  - '3.9'
  - '3.11'
  - '3.13'

defaults/Ubuntu-24.yml


# Supported versions
python_default: '3.12'
python_supported:
  - '3.12'
python_supported_deadsnakes:
  - '3.11'
  - '3.13'

defaults/Ubuntu-26.yml


# Supported versions
python_default: '3.14'
python_supported:
  - '3.14'

Example Playbook

molecule/default/converge.yml


- name: sample playbook for role 'python' pre playbook
  ansible.builtin.import_playbook: converge-pre.yml
  when: molecule_converge_pre is undefined or molecule_converge_pre | bool
- name: sample playbook for role 'python'
  hosts: all
  become: 'yes'
  vars:
    molecule_driver: '{{ lookup(''env'', ''MOLECULE_DRIVER_NAME'') }}'
    python38: true
    python39: true
    python310: true
    python311: true
    python312: true
    python313: true
    python_package_install_optional: true
    python_virtualenv_root: /tmp/venv
    python_virtualenvs:
      - name: sample
        packages:
          - dnspython
        packages_rm:
          - selinux
        python: /usr/bin/python3
        recreate: false
        site_packages: false
        user: sample
        pip_upgrade: true
  tasks:
    - name: Include role 'python'
      ansible.builtin.include_role:
        name: python