Debian Codegraph @

test/integration/targets/pip/tasks/break_system_packages.yml

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