Ansible role for installing Python from system packages or from source.
python_install_from_source: Install from source iftrue, from package iffalse(default:false)python_version: The version of python to install (only used when installing from source)python_verify_gpg_signature: If enabled, then GPG signature is verified for the downloaded tarballpython_gpg_key_id: GPG key id used to sign python tarball, optional. The known keys are stored in vars/main.yml. You need to set this option only if the requested python version is not known yet.python_force_install: Install again even if the specified version is already found
Install Python from system packages (default):
- name: Install python
hosts: localhost
become: true
roles:
- role: ansible-pythonInstall a specific Python version from source:
- name: Install python
hosts: localhost
become: true
roles:
- role: ansible-python
python_install_from_source: true
python_version: 3.11.7
python_verify_gpg_signature: trueThe role can be used multiple times with different value of
python_version to install different versions. This can be useful for
setting up an environment for testing a python lib against multiple
versions by using tox for eg.
This role uses Molecule with Docker for testing. uv is used for dependency management.
- Docker
- uv (install via
curl -LsSf https://astral.sh/uv/install.sh | sh)
# Run default test suite (install from package)
uv run molecule test
# Run install from source scenario
uv run molecule test -s install-from-source
# Test against specific distro
MOLECULE_DISTRO=ubuntu2404 uv run molecule test
MOLECULE_DISTRO=rockylinux9 uv run molecule test
# Test specific Python version (source scenario only)
MOLECULE_DISTRO=ubuntu2404 MOLECULE_PYTHON_VERSION=3.11.7 uv run molecule test -s install-from-source| Distribution | Variable Value |
|---|---|
| Ubuntu 22.04 | ubuntu2204 |
| Ubuntu 24.04 | ubuntu2404 |
| Rocky Linux 9 | rockylinux9 |
| RHEL 9 | rhel9 |
uv run ansible-lint