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
This commit is contained in:
parent
f52082abf7
commit
3a6577bada
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user