1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
- name: Get the pip version
command: "{{ ansible_python_interpreter }} -c 'import pip; print(pip.__version__)'"
register: pip_version
- when: pip_version.stdout is version("23.0.1", ">=")
block:
- name: Locate the Python externally-managed marker file
command: |
{{ ansible_python_interpreter }} -c 'import sys, sysconfig; print(f"""{sysconfig.get_path("stdlib", sysconfig.get_default_scheme()
if sys.version_info >= (3, 10) else sysconfig._get_default_scheme())}/EXTERNALLY-MANAGED""")'
register: externally_managed_marker
- name: Detect if Python is externally-managed
stat:
path: "{{ externally_managed_marker.stdout }}"
register: externally_managed
- name: Mark Python as externally managed
file:
path: "{{ externally_managed_marker.stdout }}"
state: touch
when: not externally_managed.stat.exists
- block:
- name: Copy the sample project to the target
copy:
src: sample-project/
dest: "{{ remote_sample_project }}"
- name: Attempt to pip install the sample project without a venv
pip:
name: "{{ remote_sample_project }}"
register: pip_install
failed_when: pip_install is success
- name: Attempt to pip install the sample project without a venv using break_system_packages
pip:
name: "{{ remote_sample_project }}"
break_system_packages: true
- name: Remove the sample project without using break_system_packages
pip:
name: sample-project
state: absent
register: pip_uninstall
failed_when: pip_uninstall is success
- name: Remove the sample project using break_system_packages
pip:
name: sample-project
state: absent
break_system_packages: true
always:
- name: Unmark Python as externally managed
file:
path: "{{ externally_managed_marker.stdout }}"
state: absent
when: not externally_managed.stat.exists
|