From 0cd78d0b9493856de53e514ae62c183e421fe676 Mon Sep 17 00:00:00 2001 From: Socheat Sok Date: Fri, 20 Sep 2024 15:21:16 +0700 Subject: [PATCH] Move remove EXTERNALLY-MANAGED to handler --- handlers/main.yml | 15 +++++++++++++++ tasks/main.yml | 14 +------------- 2 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 handlers/main.yml diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..a150889 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,15 @@ +--- +- name: Remove EXTERNALLY-MANAGED + block: + # 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 installed python3 version + ansible.builtin.shell: python3 --version | awk '{split($2, a, "."); print a[1] "." a[2]}' + register: py3ver + changed_when: false + + - name: Ensure "{{ 'absent' if not pip_externally_managed else 'present' }}" of EXTERNALLY-MANAGED's Python base environments + 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', '>=') diff --git a/tasks/main.yml b/tasks/main.yml index fe6b1d6..84cb6be 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,21 +1,9 @@ --- -# 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 installed python3 version - ansible.builtin.shell: python3 --version | awk '{split($2, a, "."); print a[1] "." a[2]}' - register: py3ver - changed_when: false - -- name: Ensure "{{ 'absent' if not pip_externally_managed else 'present' }}" of EXTERNALLY-MANAGED's Python base environments - 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: name: "{{ pip_package }}" state: present + notify: Remove EXTERNALLY-MANAGED - name: Ensure pip_install_packages are installed. pip: