Mohammed Naser 9254fbb5ff ensure-tox: add prefer_python2
This patch enables the ability to set a value which prefers the
installation of tox within python2 over python3.

Change-Id: I29c9585aa9048c0e2855ec1eaf1f48041cfe46e2
2020-03-04 07:21:20 +00:00

33 lines
696 B
YAML

- name: Ensure tox is installed
shell: |
set -euo pipefail
{% if tox_prefer_python2 %}
if command -v pip; then
PIP=pip
elif command -v pip3; then
PIP=pip3
fi
{% else %}
if command -v pip3; then
PIP=pip3
elif command -v pip; then
PIP=pip
fi
{% endif %}
type tox || $PIP install --user tox
args:
executable: /bin/bash
register: result
changed_when: "'Successfully installed' in result.stdout"
- name: Set tox_executable fact
set_fact:
tox_executable: "{{ ansible_user_dir }}/.local/bin/tox"
cacheable: true
when: result is changed
- name: Output tox version
command: "{{ tox_executable }} --version"