diff --git a/roles/ml-python-packages/files/tensorflow-install.sh b/roles/ml-python-packages/files/tensorflow-install.sh new file mode 100644 index 0000000000000000000000000000000000000000..4158bb336e1753cbfc67678aaade72c646fdb8f9 --- /dev/null +++ b/roles/ml-python-packages/files/tensorflow-install.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +gdownload() { + URL=$1 + OUTFILE=$2 + COOKIES="/tmp/${RANDOM}.cookie" + + if [ -z "$URL" -o -z "$OUTFILE" ]; then + return 1 + fi + + # Get cookie with skip verification code + curl -sc "$COOKIES" "$URL" &> /dev/null + + # Extract skip verification code from cookie + CODE="$(awk '/_warning_/ {print $NF}' $COOKIES)" + + echo "Code: $CODE" + + # Download the actual file + echo "Using link: " "$URL&confirm=$CODE" + curl -Lb "$COOKIES" "$URL&confirm=$CODE" -o "$OUTFILE" + + # Cleanup cookie file + rm "$COOKIES" + + return $? +} + +install() { + DLFILE="/tmp/tensorflow-2.7.0-cp39-none-linux_aarch64.whl" + + # Try to download the wheel file from google drive + if gdownload "https://drive.google.com/uc?export=download&id=1D3R7bzkuFdY_gGTkSmnF9IbRNlj9wssB" "$DLFILE"; then + # Install the downloaded wheel + pip3 install "$DLFILE" + + # Save the pip3 install return code (0 => success) + PIPRC="$?" + + # Cleanup the downloaded wheel + rm "$DLFILE" + + return $PIPRC + fi + + return 1 +} + +install diff --git a/roles/ml-python-packages/tasks/main.yml b/roles/ml-python-packages/tasks/main.yml index ccfc69093d419746b64c3a3ada29ea4d5ef6a91a..124ed9b798a15b636df1f1ab4357c150aedc2940 100644 --- a/roles/ml-python-packages/tasks/main.yml +++ b/roles/ml-python-packages/tasks/main.yml @@ -20,3 +20,21 @@ virtualenv_command: /usr/bin/python3 -m venv requirements: /tmp/ml-requirements.txt virtualenv: "/home/{{ target_user }}/.ml-venv" + + + +- name: Check if tensorflow is installed + shell: ". /home/{{ target_user }}/.ml-venv/bin/activate && pip3 freeze | grep -q tensorflow==2.7" + register: tfinstalled + changed_when: "tfinstalled.rc != 0" + failed_when: false + +- name: Copy tf install script to remote fs + copy: + src: files/tensorflow-install.sh + dest: /tmp/tensorflow-install.sh + when: "tfinstalled.rc != 0" + +- name: Download and install prebuilt tensorflow wheel + shell: ". /home/{{ target_user }}/.ml-venv/bin/activate && sh /tmp/tensorflow-install.sh" + when: "tfinstalled.rc != 0"