mirror of https://github.com/ansible/ansible.git
pip - Add break_system_packages option (#82097)
parent
3ea5304a57
commit
89cda0bcae
@ -1,2 +1,3 @@
|
||||
destructive
|
||||
shippable/posix/group2
|
||||
needs/root
|
||||
|
@ -0,0 +1,7 @@
|
||||
[project]
|
||||
name = "sample-project"
|
||||
version = "1.0.0"
|
||||
|
||||
[build-system]
|
||||
requires = ["setuptools"]
|
||||
build-backend = "setuptools.build_meta"
|
@ -0,0 +1,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
|
Loading…
Reference in New Issue