Implement a fall back URL for get-pip.py

This patch implements a fall-back URL for get-pip.py to cater for situations
where https://bootstrap.pypa.io/get-pip.py is not available (like today).

The deployer may still override the URL for the bootstrap process.

The patch also implements the fallback process in the pip_install role to
ensure that the fall back also takes place when the playbooks are run.

Change-Id: I33de85feacb633c10ed828f5d005992da6ca8a1e
This commit is contained in:
Jesse Pretorius 2015-10-07 11:22:40 +01:00
parent 922b995391
commit 392de6b035
5 changed files with 47 additions and 14 deletions

View File

@ -16,6 +16,7 @@
## Path to pip download/installation script.
pip_upstream_repo_url: https://bootstrap.pypa.io
pip_get_pip_url: "{{ pip_upstream_repo_url }}/get-pip.py"
pip_get_pip_fallback_url: https://raw.github.com/pypa/pip/master/contrib/get-pip.py
# Additional options that you might want to pass to "get-pip.py" when installing pip.
# Default `pip_get_pip_options` is an empty string.

View File

@ -43,9 +43,25 @@
url: "{{ pip_get_pip_url }}"
dest: "/opt/get-pip.py"
force: "yes"
validate_certs: "no"
validate_certs: "yes"
register: get_pip
until: get_pip|success
until: get_pip | success
ignore_errors: True
retries: 5
delay: 2
tags:
- pip-install-script
- pip-install
- name: Get Modern PIP using fallback URL
get_url:
url: "{{ pip_get_pip_fallback_url }}"
dest: "/opt/get-pip.py"
force: "yes"
validate_certs: "yes"
when: get_pip | failed
register: get_pip_fallback
until: get_pip_fallback | success
retries: 5
delay: 2
tags:
@ -56,7 +72,7 @@
shell: "python /opt/get-pip.py {{ pip_get_pip_options }}"
ignore_errors: true
register: pip_install
until: pip_install|success
until: pip_install | success
retries: 3
delay: 2
tags:
@ -66,7 +82,7 @@
shell: "python /opt/get-pip.py --isolated"
when: pip_install.rc != 0
register: pip_install_fall_back
until: pip_install_fall_back|success
until: pip_install_fall_back | success
retries: 3
delay: 2
tags:

View File

@ -26,7 +26,6 @@ export SERVICE_REGION=${SERVICE_REGION:-"RegionOne"}
export DEPLOY_OPENSTACK=${DEPLOY_OPENSTACK:-"yes"}
export DEPLOY_SWIFT=${DEPLOY_SWIFT:-"yes"}
export DEPLOY_CEILOMETER=${DEPLOY_CEILOMETER:-"yes"}
export GET_PIP_URL=${GET_PIP_URL:-"https://bootstrap.pypa.io/get-pip.py"}
export PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-$(ip route show | awk '/default/ { print $NF }')}
export PUBLIC_ADDRESS=${PUBLIC_ADDRESS:-$(ip -o -4 addr show dev ${PUBLIC_INTERFACE} | awk -F '[ /]+' '/global/ {print $4}')}
export NOVA_VIRT_TYPE=${NOVA_VIRT_TYPE:-"qemu"}
@ -148,10 +147,7 @@ if [ -d "${HOME}/.pip" ];then
fi
# Install pip
if [ ! "$(which pip)" ];then
curl ${GET_PIP_URL} > /opt/get-pip.py
python2 /opt/get-pip.py || python /opt/get-pip.py
fi
get_pip
# Install requirements if there are any
if [ -f "requirements.txt" ];then

View File

@ -24,7 +24,6 @@ export ANSIBLE_GIT_RELEASE=${ANSIBLE_GIT_RELEASE:-"v1.9.3-1"}
export ANSIBLE_GIT_REPO=${ANSIBLE_GIT_REPO:-"https://github.com/ansible/ansible"}
export ANSIBLE_ROLE_FILE=${ANSIBLE_ROLE_FILE:-"ansible-role-requirements.yml"}
export ANSIBLE_WORKING_DIR=${ANSIBLE_WORKING_DIR:-/opt/ansible_${ANSIBLE_GIT_RELEASE}}
export GET_PIP_URL=${GET_PIP_URL:-"https://bootstrap.pypa.io/get-pip.py"}
export SSH_DIR=${SSH_DIR:-"/root/.ssh"}
export UPDATE_ANSIBLE_REQUIREMENTS=${UPDATE_ANSIBLE_REQUIREMENTS:-"yes"}
export DEBIAN_FRONTEND=${DEBIAN_FRONTEND:-"noninteractive"}
@ -57,10 +56,7 @@ popd
# Install pip
if [ ! "$(which pip)" ];then
curl ${GET_PIP_URL} > /opt/get-pip.py
python2 /opt/get-pip.py || python /opt/get-pip.py
fi
get_pip
# Install requirements if there are any
if [ -f "requirements.txt" ];then

View File

@ -283,6 +283,30 @@ function print_report {
echo -e "${REPORT_DATA}"
}
function get_pip {
# if pip is already installed, don't bother doing anything
if [ ! "$(which pip)" ]; then
# if GET_PIP_URL is set, then just use it
if [ -z "${GET_PIP_URL:-}" ]; then
# Find and use an available get-pip download location.
if curl --silent https://bootstrap.pypa.io/get-pip.py; then
export GET_PIP_URL='https://bootstrap.pypa.io/get-pip.py'
elif curl --silent https://raw.github.com/pypa/pip/master/contrib/get-pip.py; then
export GET_PIP_URL='https://raw.github.com/pypa/pip/master/contrib/get-pip.py'
else
echo "A suitable download location for get-pip.py could not be found."
exit_fail
fi
fi
# Download and install pip
curl ${GET_PIP_URL} > /opt/get-pip.py
python2 /opt/get-pip.py || python /opt/get-pip.py
fi
}
## Signal traps --------------------------------------------------------------
# Trap all Death Signals and Errors