Skip to content

Commit

Permalink
Bootstrap Ansible with Python3 on Ubuntu
Browse files Browse the repository at this point in the history
Update the bootstrap-ansible script to install equivalent Python3 distro
packages on Ubuntu and default to Python3 when creating the Ansible
virtualenv. If an existing virtulenv exists with a differing version of
Python, fully remove it for a cleaner installation.

Change-Id: I06cf934b3af1005d4b2adec76e22f249b72a69ec
Implements: blueprint goal-python35
Depends-On: I8874c439fc9c006125bb39ff6a2cd386bfc8f561
Depends-On: I7270eef4b03fdd4cdf8b578edb479ecb336b6a83
Depends-On: If2484febbab4db20539749094517240b5f17d1ab
  • Loading branch information
jimmymccrory committed Jun 28, 2017
1 parent 0648818 commit 5b9d96e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 11 additions & 12 deletions scripts/bootstrap-ansible.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,13 @@ case ${DISTRO_ID} in
ubuntu)
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y install \
git python-all python-dev curl python2.7-dev build-essential \
libssl-dev libffi-dev netcat python-requests python-openssl python-pyasn1 \
python-netaddr python-prettytable python-crypto python-yaml \
python-virtualenv
git python3-all python3-dev curl python3.5-dev build-essential \
libssl-dev libffi-dev netcat python3-requests python3-openssl python3-pyasn1 \
python3-netaddr python3-prettytable python3-crypto python3-yaml \
python3-virtualenv
;;
esac

# NOTE(mhayden): Ubuntu 16.04 needs python-ndg-httpsclient for SSL SNI support.
# This package is not needed in Ubuntu 14.04 and isn't available
# there as a package.
if [[ "${DISTRO_ID}" == 'ubuntu' ]] && [[ "${DISTRO_VERSION_ID}" == '16.04' ]]; then
DEBIAN_FRONTEND=noninteractive apt-get -y install python-ndg-httpsclient
fi

# Install pip
get_pip

Expand All @@ -96,7 +89,7 @@ elif [ -n "$HTTP_PROXY" ]; then
fi

# Figure out the version of python is being used
PYTHON_EXEC_PATH="$(which python2 || which python)"
PYTHON_EXEC_PATH="$(which python3 || which python2 || which python)"
PYTHON_VERSION="$($PYTHON_EXEC_PATH -c 'import sys; print(".".join(map(str, sys.version_info[:3])))')"

# Use https when Python with native SNI support is available
Expand All @@ -106,6 +99,12 @@ UPPER_CONSTRAINTS_PROTO=$([ "$PYTHON_VERSION" == $(echo -e "$PYTHON_VERSION\n2.7
export UPPER_CONSTRAINTS_FILE=${UPPER_CONSTRAINTS_FILE:-"$UPPER_CONSTRAINTS_PROTO://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?id=$(awk '/requirements_git_install_branch:/ {print $2}' playbooks/defaults/repo_packages/openstack_services.yml)"}

# Create a Virtualenv for the Ansible runtime
if [ -f "/opt/ansible-runtime/bin/python" ]; then
VENV_PYTHON_VERSION="$(/opt/ansible-runtime/bin/python -c 'import sys; print(".".join(map(str, sys.version_info[:3])))')"
if [ "$PYTHON_VERSION" != "$VENV_PYTHON_VERSION" ]; then
rm -rf /opt/ansible-runtime
fi
fi
virtualenv --clear ${VIRTUALENV_OPTIONS} --python="${PYTHON_EXEC_PATH}" /opt/ansible-runtime

# The vars used to prepare the Ansible runtime venv
Expand Down
2 changes: 2 additions & 0 deletions tests/roles/bootstrap-host/vars/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ packages_install:
- linux-image-extra-{{ ansible_kernel }}
- lvm2
- python2.7
- python-crypto
- python-dev
- python-yaml
- sshpass
- tmux
- vim
Expand Down

0 comments on commit 5b9d96e

Please sign in to comment.