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
This commit is contained in:
Ian Wienand 2020-05-01 09:09:59 +10:00
parent d775467078
commit b4c195b419
6 changed files with 25 additions and 7 deletions

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -7,5 +7,4 @@
package:
name: python2-pip
become: yes
when:
- ensure_pip_from_packages_with_python2
when: ensure_pip_from_packages_with_python2

View File

@ -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:

View File

@ -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'