Explicitely set ansible version to use

Remove the outdated ansible-pip-str.py and rely directly on
ANSIBLE_PIP_VERSION to set the installed version of ansible.

Change-Id: I105b85595cfea101bdb747113721536f4a3ef93a
This commit is contained in:
Riccardo Pittau 2020-03-05 17:23:09 +01:00
parent 74f8005978
commit adf964481e
3 changed files with 12 additions and 61 deletions

View File

@ -0,0 +1,7 @@
---
upgrade:
- |
Define a default ansible version to install using DEFAULT_PIP_ANSIBLE
variable, but allow override it either using a schema understood by pip
using ANSIBLE_PIP_VERSION, or setting a local path or a remote url using
ANSIBLE_SOURCE_PATH.

View File

@ -1,57 +0,0 @@
#!/usr/bin/env python
# Copyright (c) 2017 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Helper script to choose which ansible version to install for bifrost"""
from __future__ import print_function
import sys
import six
in_str = sys.argv[1]
HELP_MSG = ("Unsupported version or format %s - "
"Supporting format [stable-]MAJ.MIN where MAJ.MIN is 1.9 or 2.x"
% in_str)
if in_str.startswith('stable-'):
in_version = in_str.split('stable-')[1]
else:
if six.text_type(in_str[0]).isdecimal():
print("ansible==%s" % in_str)
else:
print("ansible%s" % in_str)
sys.exit(0)
if len(in_version) != 3 and in_version[1] != '.':
print(HELP_MSG)
sys.exit(1)
else:
maj_version = in_version[0]
try:
min_version = int(in_version[2])
except ValueError:
print(HELP_MSG)
sys.exit(1)
if maj_version == '1' and min_version == 9:
upper_bound = '2.0'
elif maj_version == '2':
upper_bound = '2.%i' % (min_version + 1)
else:
print(HELP_MSG)
sys.exit(1)
print("ansible<%s" % upper_bound)

View File

@ -5,15 +5,16 @@ set -eu
# NOTE(pas-ha) the above exports some useful variables like
# $PYTHON , $PIP and $VENV depending on venv install or not
ANSIBLE_PIP_VERSION=${ANSIBLE_PIP_VERSION:-${ANSIBLE_GIT_BRANCH:-stable-2.8}}
DEFAULT_PIP_ANSIBLE='!=2.8.9,<2.9'
ANSIBLE_PIP_STRING=$(${PYTHON} $(dirname $0)/ansible-pip-str.py ${ANSIBLE_PIP_VERSION})
ANSIBLE_PIP_VERSION=${ANSIBLE_PIP_VERSION:-${DEFAULT_PIP_ANSIBLE}}
ANSIBLE_SOURCE_PATH=${ANSIBLE_SOURCE_PATH:-ansible${ANSIBLE_PIP_VERSION}}
if [ -n "${VENV-}" ]; then
sudo ${PIP} install --ignore-installed "${ANSIBLE_PIP_STRING}"
sudo ${PIP} install --ignore-installed "${ANSIBLE_SOURCE_PATH}"
ANSIBLE=${VENV}/bin/ansible
else
${PIP} install --user --upgrade "${ANSIBLE_PIP_STRING}"
${PIP} install --user --upgrade "${ANSIBLE_SOURCE_PATH}"
ANSIBLE=${HOME}/.local/bin/ansible
fi