From 3a6577badacd8f2d03ec2eaaf1336c27a8c1479d Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Tue, 26 Nov 2019 17:18:02 +0000 Subject: [PATCH] Support python 3 in kolla-ansible script The kolla-ansible script uses a python interpreter to detect the location of playbooks and to check that the kolla_ansible python module is importable. This change updates the script to support a python interpreter named python or python3. Partially Implements: blueprint python-3 Change-Id: Id5dcc53cc5dd9780632c04b6b73c56ea5da484a2 --- tools/kolla-ansible | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/kolla-ansible b/tools/kolla-ansible index 5e1cd1edc5..2bc0ada170 100755 --- a/tools/kolla-ansible +++ b/tools/kolla-ansible @@ -3,7 +3,10 @@ # This script can be used to interact with kolla via ansible. function find_base_dir { - local real_path=$(python -c "import os;print(os.path.realpath('$0'))") + # $1: Python interpreter + local python + python=$1 + local real_path=$($python -c "import os;print(os.path.realpath('$0'))") local dir_name="$(dirname "$real_path")" if [ -z "$SNAP" ]; then if [[ ${dir_name} == "/usr/bin" ]]; then @@ -120,14 +123,21 @@ LONG_OPTS="help,inventory:,playbook:,skip-tags:,tags:,key:,extra:,verbose,config RAW_ARGS="$*" ARGS=$(getopt -o "${SHORT_OPTS}" -l "${LONG_OPTS}" --name "$0" -- "$@") || { usage >&2; exit 2; } -if ! python -c 'import kolla_ansible' &>/dev/null; then +# Detect which python interpreter to use. +for python in python3 python2; do + if $python -c 'import kolla_ansible' &>/dev/null; then + PYTHON=$python + break + fi +done +if [[ -z $PYTHON ]]; then echo "ERROR: kolla_ansible has to be available in the PYTHONPATH (e.g. installed)" >&2 exit 1 fi eval set -- "$ARGS" -find_base_dir +find_base_dir $PYTHON INVENTORY="${BASEDIR}/ansible/inventory/all-in-one" PLAYBOOK="${BASEDIR}/ansible/site.yml"