Rework "externally managed" python base environment

This commit is contained in:
Socheat Sok 2024-05-15 15:38:10 +07:00
parent d5d1d2e4dd
commit a2b57a6869
No known key found for this signature in database
GPG Key ID: 8967527396F3D1B5
4 changed files with 17 additions and 18 deletions

View File

@ -18,6 +18,10 @@ The name of the package to install to get `pip` on the system. For older systems
pip_executable: pip3
Marking Python base environments as "externally managed".
pip_externally_managed: true
The role will try to autodetect the pip executable based on the `pip_package` (e.g. `pip` for Python 2 and `pip3` for Python 3). You can also override this explicitly, e.g. `pip_executable: pip3.6`.
pip_install_packages: []

View File

@ -3,4 +3,5 @@
pip_package: python3-pip
pip_executable: "{{ 'pip3' if pip_package.startswith('python3') else 'pip' }}"
pip_externally_managed: true
pip_install_packages: []

View File

@ -1,13 +0,0 @@
---
# Remove EXTERNALLY-MANAGED file if we're on Debian12
# Related issue: https://github.com/geerlingguy/ansible-role-pip/issues/57
- name: Get python3 version installed
ansible.builtin.command: python3 --version
register: py3ver
changed_when: false
- name: Remove EXTERNALLY-MANAGED
ansible.builtin.file:
path: /usr/lib/python3.11/EXTERNALLY-MANAGED
state: absent
when: py3ver is defined and py3ver.stdout.find("3.11") != -1

View File

@ -1,9 +1,16 @@
---
- name: Remove externally managed from Debian 12
ansible.builtin.import_tasks: debian12.yml
when:
- ansible_distribution == "Debian"
- ansible_distribution_major_version|int >= 12
# Remove EXTERNALLY-MANAGED if pip_externally_managed is true and python3 version is 3.11 or higher.
# Related issue: https://github.com/geerlingguy/ansible-role-pip/issues/57
- name: Get python3 version installed
ansible.builtin.shell: python3 --version | awk '{split($2, a, "."); print a[1] "." a[2]}'
register: py3ver
changed_when: false
- name: Remove EXTERNALLY-MANAGED
ansible.builtin.file:
path: "/usr/lib/python{{ py3ver.stdout }}/EXTERNALLY-MANAGED"
state: "{{ 'absent' if not pip_externally_managed else 'touch' }}"
when: py3ver is defined and py3ver.stdout is version_compare('3.11', '>=')
- name: Ensure Pip is installed.
package: