Skip to content

Commit 7a60870

Browse files
committed
workaround failure of get_url on python 2.7.6 hosts
golang.org download URLs do not serve the correct TLS certificate unless TLS SNI is used. The TLS client in Python 2.7.6 doesn't support TLS SNI and so reports an certificate validation error. Fortunately, the golang.org URL is actually a redirect to a different URL which does export the correct certificate even without SNI. This change adjusts the specified download URL to take account of which version of python is installed on the host by fallowing the redirect with curl, defaulting to the original URL if this process does not work for some reason. Signed-off-by: Jon Seymour <jon@wildducktheories.com>
1 parent 3b47945 commit 7a60870

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

files/resolve-redirect.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
PYTHON_VERSION=$1
3+
URL=$2
4+
5+
# golang URLs are behind a redirect that requires clients
6+
# that support TLS SNI which Python 2.7.6 found on
7+
# most Ubuntu 14.04 installations does not support.
8+
# get_url will fail if executed against the original URL
9+
# but will succeed with the final URL
10+
11+
test "$PYTHON_VERSION" "<" "2.7.9" &&
12+
url=$(curl -s -I "$URL" | sed -n "s/Location: //p") &&
13+
test -n "$url" &&
14+
URL="$url"; echo "$URL"

tasks/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---
2+
- name: Resolve redirect early for Python < 2.7.9
3+
script: files/resolve-redirect.sh {{ ansible_python_version }} {{ go_download_location }}
4+
register: go_download_location_adjusted
5+
26
- name: Download the Go tarball
3-
get_url: url={{ go_download_location }}
7+
get_url: url={{ go_download_location_adjusted.stdout }}
48
dest=/usr/local/src/{{ go_tarball }}
59
sha256sum={{ go_tarball_checksum }}
610

vars/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
go_download_location: "https://storage.googleapis.com/golang/{{ go_tarball }}"
2+
go_download_location: "https://golang.org/dl/{{ go_tarball }}"

0 commit comments

Comments
 (0)