From b4c195b4193766d4b7f45300389d711cae7f07bb Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 1 May 2020 09:09:59 +1000 Subject: [PATCH] ensure-pip: use python2-pip when running under Python 2 When Ansible runs under Python 2, such as on SuSE 15, we need python2-pip for pip: to work. Update the default to install Python 2 deps when Ansible is running under v2. Additionally for SuSE, as described inline we can have pip but not setuptools. Put in a work-around to always pull in the setuptools package. Pull this out into a separate file; history has shown that we may need more :/ Change-Id: I450171aad5e31d2925239ab3d0641cd23f6815a2 --- roles/ensure-pip/defaults/main.yaml | 2 +- roles/ensure-pip/tasks/Debian.yaml | 3 +-- roles/ensure-pip/tasks/RedHat.yaml | 3 +-- roles/ensure-pip/tasks/Suse.yaml | 3 +-- roles/ensure-pip/tasks/main.yaml | 3 +++ roles/ensure-pip/tasks/workarounds.yaml | 18 ++++++++++++++++++ 6 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 roles/ensure-pip/tasks/workarounds.yaml diff --git a/roles/ensure-pip/defaults/main.yaml b/roles/ensure-pip/defaults/main.yaml index 2d92a5e38..103e1ff96 100644 --- a/roles/ensure-pip/defaults/main.yaml +++ b/roles/ensure-pip/defaults/main.yaml @@ -1,5 +1,5 @@ ensure_pip_from_packages: True -ensure_pip_from_packages_with_python2: False +ensure_pip_from_packages_with_python2: '{{ (ansible_python.version.major == 2) | ternary(True, False) }}' ensure_pip_from_upstream_url: 'https://bootstrap.pypa.io/get-pip.py' ensure_pip_from_upstream: False ensure_pip_from_upstream_interpreters: diff --git a/roles/ensure-pip/tasks/Debian.yaml b/roles/ensure-pip/tasks/Debian.yaml index d70a07552..95b292a6f 100644 --- a/roles/ensure-pip/tasks/Debian.yaml +++ b/roles/ensure-pip/tasks/Debian.yaml @@ -12,5 +12,4 @@ - python-setuptools - python-pip become: yes - when: (ensure_pip_from_packages_with_python2) or - (ansible_python.version.major == 2) + when: ensure_pip_from_packages_with_python2 diff --git a/roles/ensure-pip/tasks/RedHat.yaml b/roles/ensure-pip/tasks/RedHat.yaml index cf976ce14..cffe44205 100644 --- a/roles/ensure-pip/tasks/RedHat.yaml +++ b/roles/ensure-pip/tasks/RedHat.yaml @@ -16,5 +16,4 @@ - python-virtualenv state: present become: yes - when: (ensure_pip_from_packages_with_python2) or - (ansible_python.version.major == 2) + when: ensure_pip_from_packages_with_python2 diff --git a/roles/ensure-pip/tasks/Suse.yaml b/roles/ensure-pip/tasks/Suse.yaml index 7dacfe319..8eb1109d8 100644 --- a/roles/ensure-pip/tasks/Suse.yaml +++ b/roles/ensure-pip/tasks/Suse.yaml @@ -7,5 +7,4 @@ package: name: python2-pip become: yes - when: - - ensure_pip_from_packages_with_python2 + when: ensure_pip_from_packages_with_python2 diff --git a/roles/ensure-pip/tasks/main.yaml b/roles/ensure-pip/tasks/main.yaml index 74df1d9c0..8c572d6cd 100644 --- a/roles/ensure-pip/tasks/main.yaml +++ b/roles/ensure-pip/tasks/main.yaml @@ -37,6 +37,9 @@ - ensure_pip_from_packages - pip_preinstalled.rc != 0 +- name: Include workarounds + include: workarounds.yaml + - name: Install pip from source include: source.yaml when: diff --git a/roles/ensure-pip/tasks/workarounds.yaml b/roles/ensure-pip/tasks/workarounds.yaml new file mode 100644 index 000000000..d06285bf3 --- /dev/null +++ b/roles/ensure-pip/tasks/workarounds.yaml @@ -0,0 +1,18 @@ +# +# This file contains workaround tasks for specific issues +# + +# Somehow on SuSE 15 the dependencies are such that python2-pip can be +# installed, but setuptools is not. This breaks Ansible's pip: which +# does a direct import of pkg_resources and thus has a hard-dependency +# on setuptools. This doesn't appear to happen for python3. Thus we +# ensure this is installed, even if we skipped install phase because +# pip looked like it was installed already. +- name: Ensure setuptools + package: + name: python-setuptools + become: yes + when: + - ansible_python.version.major == 2 + - ansible_os_family == 'Suse' + - ansible_distribution_major_version == '15'