Skip to content

Set default Ansible Python interpreter#1665

Open
retlehs wants to merge 1 commit into
masterfrom
python-interpreter
Open

Set default Ansible Python interpreter#1665
retlehs wants to merge 1 commit into
masterfrom
python-interpreter

Conversation

@retlehs
Copy link
Copy Markdown
Member

@retlehs retlehs commented Apr 27, 2026

Summary

Sets Trellis' default Ansible Python interpreter to the stable Ubuntu system Python path:

ansible_python_interpreter: /usr/bin/python3

This avoids Ansible interpreter discovery warnings during provisioning while keeping the value in project vars, where projects can still override it per environment or host if needed.

Current warning

Without an explicit interpreter, Ansible can emit this during provision:

TASK [Gathering Facts] *********************************************************
[WARNING]: Platform linux on host 159.203.174.217 is using the discovered
Python interpreter at /usr/bin/python3.12, but future installation of another
Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible-
core/2.18/reference_appendices/interpreter_discovery.html for more information.
ok: [159.203.174.217]

Related issues

  • 2018-12-05 #1034 reported remote provisioning failures after Trellis changed remote interpreter handling during the Python 2/3 transition. The fix was #1036, which removed the server.yml interpreter setup because Trellis still installed Python 2-specific packages on servers at the time.
  • 2021-01-26 #1267 reported Vagrant provisioning failures from pip/Python 2 behavior. The fix was #1269, which forced Vagrant's local Ansible provisioner to use Python 3.
  • 2022-03-11 #1371 reported hosts using the wrong Python interpreter after the old python_interpreter role was removed. The issue mentions interpreter_python = /usr/bin/python3 and per-host ansible_python_interpreter=/usr/bin/python3 as workarounds, and was closed after #1373 allowed newer Ansible versions with improved interpreter discovery.
  • 2024-06-19 #1525 reported an Ansible 2.17 deploy failure where Ansible selected /usr/bin/python3.8; the reporter confirmed that adding ansible_python_interpreter=/usr/bin/python3 to the host fixed it.

Related PR history

  • 2018-12-05 #1033 - "Python version compatibility fixes": changed the remote setup to find python3 || python and set ansible_python_interpreter from the discovered path.
  • 2018-12-09 #1036 - "Remove ansible_python_interpreter in server.yml": removed that dynamic server.yml interpreter setup because Python 2-specific remote packages still made Python 3 unsafe on some supported servers.
  • 2018-12-12 #992 - "Ubuntu 18.04" (Python version compatibility): added a server.yml task that set ansible_python_interpreter: python3 for Ubuntu 18.04/Bionic hosts.
  • 2018-12-13 #1039 - "Fix Ubuntu 18.04 python interpreter" (Set ansible_python_interpreter in dev): reintroduced interpreter handling through a python_interpreter role and added it to development provisioning.
  • 2020-08-06 #1211 - "Improve python interpreter check": updated the role from an Ubuntu 18.04/Bionic codename check to an Ubuntu >= 18.04 version check.
  • 2021-01-30 #1269 - "Use Python 3 for ansible_local Vagrant provisioner" (Vagrant: use python3): set Vagrant's ansible_python_interpreter default to /usr/bin/python3.
  • 2022-02-20 #1361 - "Remove Python 2 support": removed the python_interpreter role and its plays because Python 3 became a Trellis requirement.
  • 2026-01-13 #1620 - "Ansible 2.19 support": set ansible_python_interpreter=/usr/bin/python3 in the CI inventory so local CI runs use system Python where apt-installed Python packages are available.

@retlehs retlehs requested a review from swalkinshaw April 27, 2026 03:45
@retlehs retlehs self-assigned this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant