78 lines
2.4 KiB
YAML
78 lines
2.4 KiB
YAML
- name: Check if pip is installed
|
|
shell: |
|
|
PYTHON2=0
|
|
PYTHON3=1
|
|
{% if ensure_pip_from_packages and ensure_pip_from_packages_with_python2 %}
|
|
PYTHON2=1
|
|
{% elif ensure_pip_from_upstream and 'python2' in ensure_pip_from_upstream_interpreters %}
|
|
PYTHON2=1
|
|
{% endif %}
|
|
{% if ensure_pip_from_upstream and 'python3' not in ensure_pip_from_upstream_interpreters %}
|
|
PYTHON3=0
|
|
{% endif %}
|
|
|
|
# Not all platforms install a `pip` when installing python
|
|
# specific pip packages. We first check if pip$VERSION is
|
|
# available and if not fallback to checking if just `pip`
|
|
# is present.
|
|
if [ "$PYTHON2" -eq "1" ] ; then
|
|
command -v pip2 || command -v pip || exit 1
|
|
fi
|
|
if [ "$PYTHON3" -eq "1" ] ; then
|
|
command -v pip3 || command -v pip || exit 1
|
|
fi
|
|
args:
|
|
executable: /bin/bash
|
|
register: pip_preinstalled
|
|
failed_when: false
|
|
|
|
- name: Install pip from packages
|
|
include: "{{ zj_distro_os }}"
|
|
with_first_found:
|
|
- "{{ ansible_distribution_release }}.yaml"
|
|
- "{{ ansible_distribution }}.yaml"
|
|
- "{{ ansible_os_family }}.yaml"
|
|
- "default.yaml"
|
|
when:
|
|
- ensure_pip_from_packages
|
|
- pip_preinstalled.rc != 0
|
|
loop_control:
|
|
loop_var: zj_distro_os
|
|
|
|
- name: Install pip from source
|
|
include: source.yaml
|
|
when:
|
|
- ensure_pip_from_upstream
|
|
- pip_preinstalled.rc != 0
|
|
|
|
#
|
|
# virtualenv setup
|
|
#
|
|
- name: Probe for venv
|
|
command: /usr/bin/python3 -m venv --help
|
|
no_log: True
|
|
failed_when: false
|
|
register: _venv_probe
|
|
|
|
- name: Set host default
|
|
set_fact:
|
|
_host_virtualenv: '{{ (_venv_probe.rc == 0) | ternary("/usr/bin/python3 -m venv", "virtualenv") }}'
|
|
when: ansible_distribution_release != 'xenial'
|
|
|
|
# The pip included with Xenial (version ~8) has issues with our wheel
|
|
# mirrors; it will not correctly look to upstream pypi when it can't
|
|
# find the wheel in the configured mirror, so virutalenv creation
|
|
# fails. venv uses the system pip version; for this reason we need to
|
|
# use virtualenv which does upgrade pip in the environment; but note
|
|
# that on Xenial "virtualenv" is owned by the python2 package; so we
|
|
# specify the command to python3 directly.
|
|
- name: Set host default (Xenial)
|
|
set_fact:
|
|
_host_virtualenv: '/usr/bin/python3 -m virtualenv'
|
|
when: ansible_distribution_release == 'xenial'
|
|
|
|
- name: Set ensure_pip_virtualenv_cmd
|
|
set_fact:
|
|
ensure_pip_virtualenv_command: '{{ ensure_pip_virtualenv_command | default(_host_virtualenv) }}'
|
|
cacheable: true
|