zuul-jobs/roles/ensure-pip/tasks/workarounds.yaml
James E. Blair 82d3910b17 More narrowly tailor the ensure-pip Debian workaround
The docker image that we build the zuul executor from is a Debian
image, but it does not follow the same python3 policies as Debian
itself.  While we would not necessarily expect all roles to work
on the executor, it is reasonable to want to use the ensure-pip
role (which logically should be a no-op on the executor) for the
side effect of finding and returning the appropriate pip command.

Currently, the role fails on the executor because it mistakenly
concludes that it must install python3-venv to get a working
venv module.  By increasing the precision of the check for what
is missing (the actual error is a missing "ensurepip" python module
(oh irony!), we can avoid attempting an installation of
python3-venv on python docker images (including the Zuul executor
images).

This also adds the ensure-pip-localhost job

This tests that the ensure-pip role works on the Zuul executor.

The executor is a debian host with a working python environment,
so it should be a no-op (and no packages should need to be installed).

Change-Id: Id7f13f2f73d45e680f79c00a83751b185212a63d
2022-10-04 11:35:24 -07:00

46 lines
1.6 KiB
YAML

#
# 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'
# Part of this role is exporting a working virtualenv_command for you
# -- on Debuntu, the presence of venv (i.e. "python3 -m venv --help"
# works) doesn't actually mean venv works. When "python3 -m venv foo"
# is run, venv construction will fail because the "ensurepip" module
# is not present.
#
# It's quite possible we have pip and so have skipped installing from
# packages, where we would have brought this in. To avoid requiring
# sudo, which is the whole point of probing for pip and skipping
# install if we have it, we probe for "ensurepip" here and only
# install the package if required.
- name: Check for ensurepip module
command: python3 -m ensurepip --help
failed_when: false
register: _ensurepip_module
when:
- ansible_os_family == 'Debian'
- name: Ensure python3-venv
package:
name:
- python3-venv
become: yes
when:
- ansible_os_family == 'Debian'
- _ensurepip_module.rc != 0