Look for python3 by default

This patch improves the required package installing task - search
first for a py3 and verify a virtualenv package is installed too.
If no py3, check py2 and py2 virtualenv respectively.

Change-Id: I7abc59f2edb0c4409ea67ac4b611a95779bef714
This commit is contained in:
Martin Kopec 2020-12-10 00:31:08 +00:00
parent 3a7b72ba93
commit 3d592d6a8b
3 changed files with 25 additions and 20 deletions

View File

@ -1,42 +1,44 @@
--- ---
- name: Is python available - name: Is python3 available
command: "python --version" command: "python3 --version"
ignore_errors: true ignore_errors: true
register: python_is_available register: python3_is_available
changed_when: false changed_when: false
- name: Is python2 available
command: "python2 --version"
ignore_errors: true
changed_when: false
when: python3_is_available.failed
- name: Install git - name: Install git
become: true become: true
package: package:
name: git name: git
- name: Install virtualenv - name: Install virtualenv (py3)
become: true
package:
name: python-virtualenv
when: python_is_available.rc == 0
- name: Install virtualenv
become: true become: true
package: package:
name: python3-virtualenv name: python3-virtualenv
when: python_is_available.rc != 0 when: not python3_is_available.failed
- name: Install virtualenv (py2)
become: true
package:
name: python-virtualenv
when: python3_is_available.failed
- name: Check if pip is already installed - name: Check if pip is already installed
command: "pip --version" command: "pip --version"
ignore_errors: true ignore_errors: true
register: pip_is_installed register: pip_is_installed
changed_when: false when: python3_is_available.failed
- name: Check if pip3 is already installed
command: "pip3 --version"
ignore_errors: true
register: pip3_is_installed
changed_when: false
# pip3 is a dependency of a python3 package, so if there is a python3
# installed, pip3 should be installed already as well
- when: - when:
- python3_is_available.failed
- pip_is_installed.rc != 0 - pip_is_installed.rc != 0
- pip3_is_installed.rc != 0
block: block:
- name: download get-pip.py - name: download get-pip.py
get_url: url=https://bootstrap.pypa.io/get-pip.py dest=/tmp get_url: url=https://bootstrap.pypa.io/get-pip.py dest=/tmp

View File

@ -30,5 +30,5 @@
- name: Check if we passed refstack tests - name: Check if we passed refstack tests
fail: fail:
msg: "Refstack tests failed." msg: "Refstack tests failed."
# the refstack_result var got set in run_refstack_client.yaml # the refstack_result var got set in run-refstack-client.yaml
when: refstack_result.rc > 0 when: refstack_result.rc > 0

View File

@ -46,5 +46,8 @@
chdir: "{{ refstack_client_source }}" chdir: "{{ refstack_client_source }}"
executable: /bin/bash executable: /bin/bash
register: refstack_result register: refstack_result
# don't fail here in order to allow post_tasks be executed,
# the refstack_result is inspected in the last task of the role where it
# fails if it failed here
ignore_errors: true ignore_errors: true
when: test_list is not defined when: test_list is not defined