From 3d592d6a8b3c131c6b5e46afa78ebebcb11d39e9 Mon Sep 17 00:00:00 2001 From: Martin Kopec Date: Thu, 10 Dec 2020 00:31:08 +0000 Subject: [PATCH] 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 --- tasks/install-packages.yaml | 40 ++++++++++++++++++---------------- tasks/main.yaml | 2 +- tasks/run-refstack-client.yaml | 3 +++ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/tasks/install-packages.yaml b/tasks/install-packages.yaml index 51ddace..5388385 100644 --- a/tasks/install-packages.yaml +++ b/tasks/install-packages.yaml @@ -1,42 +1,44 @@ --- -- name: Is python available - command: "python --version" +- name: Is python3 available + command: "python3 --version" ignore_errors: true - register: python_is_available + register: python3_is_available changed_when: false +- name: Is python2 available + command: "python2 --version" + ignore_errors: true + changed_when: false + when: python3_is_available.failed + - name: Install git become: true package: name: git -- name: Install virtualenv - become: true - package: - name: python-virtualenv - when: python_is_available.rc == 0 - -- name: Install virtualenv +- name: Install virtualenv (py3) become: true package: 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 command: "pip --version" ignore_errors: true register: pip_is_installed - changed_when: false - -- name: Check if pip3 is already installed - command: "pip3 --version" - ignore_errors: true - register: pip3_is_installed - changed_when: false + when: python3_is_available.failed +# pip3 is a dependency of a python3 package, so if there is a python3 +# installed, pip3 should be installed already as well - when: + - python3_is_available.failed - pip_is_installed.rc != 0 - - pip3_is_installed.rc != 0 block: - name: download get-pip.py get_url: url=https://bootstrap.pypa.io/get-pip.py dest=/tmp diff --git a/tasks/main.yaml b/tasks/main.yaml index defe867..b1de0b4 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -30,5 +30,5 @@ - name: Check if we passed refstack tests fail: 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 diff --git a/tasks/run-refstack-client.yaml b/tasks/run-refstack-client.yaml index 6bcba06..456b72a 100644 --- a/tasks/run-refstack-client.yaml +++ b/tasks/run-refstack-client.yaml @@ -46,5 +46,8 @@ chdir: "{{ refstack_client_source }}" executable: /bin/bash 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 when: test_list is not defined