Skip to content

Commit

Permalink
Move remove EXTERNALLY-MANAGED to handler
Browse files Browse the repository at this point in the history
  • Loading branch information
socheatsok78 committed Sep 20, 2024
1 parent ceea3d9 commit 0cd78d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
15 changes: 15 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 11 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

11:121 [line-length] line too long (129 > 120 characters)
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', '>=')
14 changes: 1 addition & 13 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 0cd78d0

Please sign in to comment.