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"