diff --git a/tools/ansible.sh b/tools/ansible.sh old mode 100644 new mode 100755 index 9246573..3f06f8a --- a/tools/ansible.sh +++ b/tools/ansible.sh @@ -8,12 +8,61 @@ fi CODENAME=$(lsb_release -c -s) + +is_core() { + grep -qFx 'ID=ubuntu-core' /etc/os-release +} + +is_classic() { + ! is_core +} + +is_ubuntu_ge() { + is_classic && compare_ubuntu "${1:-}" "-ge" +} + +compare_ubuntu() { + VERSION=$1 + OPERAND=$2 + + if [ -z "$VERSION" ]; then + echo "os.query: version id is expected" + exit 1 + fi + + if ! grep -q 'ID=ubuntu' /etc/os-release; then + echo "os.query: comparing non ubuntu system" + return 1 + fi + + NUM_RE='^[0-9]+$' + NUM_VERSION="$(echo "$VERSION" | tr -d '".')" + if ! [[ $NUM_VERSION =~ $NUM_RE ]] ; then + echo "os.query: invalid version format \"$VERSION\" provided" + exit 1 + fi + + SYS_VERSION="$(grep 'VERSION_ID' /etc/os-release)" + SYS_VERSION="$(echo "${SYS_VERSION#*=}" | tr -d '".')" + if ! [[ $SYS_VERSION =~ $NUM_RE ]] ; then + echo "os.query: invalid version format \"$SYS_VERSION\" retrieved from system" + exit 1 + fi + + test "$SYS_VERSION" "$OPERAND" "$NUM_VERSION" +} + +is_ubuntu_ge_22_04() { + is_ubuntu_ge "22.04" +} + PY_FLAG=$1 IS_TRUSTY() { [ "${CODENAME}" == "trusty" ]; } IS_XENIAL() { [ "${CODENAME}" == "xenial" ]; } IS_BIONIC() { [ "${CODENAME}" == "bionic" ]; } -IS_JAMMY() { [ "${CODENAME}" == "jammy" ]; } +IS_JAMMY() { [ "${CODENAME}" == "jammy" ]; } # 22.04 +IS_RESOLUTE() { [ "${CODENAME}" == "resolute" ]; } # 26.04 USE_PYTHON3() { [ "${PY_FLAG}" == "python3" ]; } do_cmd() @@ -65,6 +114,10 @@ if IS_JAMMY; then ansible --version | grep -q '2.10' 2> /dev/null is_ansible_right=$? fi +if IS_RESOLUTE; then + ansible --version | grep -q '2.20' 2> /dev/null + is_ansible_right=$? +fi if [ $is_ansible_right -ne 0 ]; then do_cmd sudo apt-get update @@ -83,7 +136,7 @@ if [ $is_ansible_right -ne 0 ]; then do_cmd sudo apt-get -y install wget python python-crypto python-yaml python-httplib2 python-setuptools python-markupsafe python-jinja2 python-paramiko sshpass do_cmd sudo wget -O /tmp/ansible.deb https://raw.githubusercontent.com/codio/install_software/${BRANCH}/tools/ansible_2.7.5-1ppa_bionic_all.deb fi - if IS_JAMMY; then + if is_ubuntu_ge_22_04; then do_cmd sudo apt update do_cmd sudo apt install -y ansible else @@ -96,7 +149,7 @@ download_playbook do_cmd sudo apt-get update -if USE_PYTHON3 || IS_JAMMY; then +if USE_PYTHON3 || is_ubuntu_ge_22_04; then sudo ansible-playbook -v "${COOKBOOK_PATH}/install_software-${BRANCH}/$0/playbook.yaml" -e 'ansible_python_interpreter=/usr/bin/python3' elif IS_TRUSTY; then sudo ansible-playbook -v "${COOKBOOK_PATH}/install_software-${BRANCH}/$0/playbook.yaml"