Skip to content

Commit

Permalink
Use a proper Ansible version comparison (because stringwise, 2.8.10<2…
Browse files Browse the repository at this point in the history
….8.4) (StreisandEffect#1770)

(Also, you can't 'apt-get install python' without doing an 'apt-get update' first.)
  • Loading branch information
nopdotcom authored Apr 11, 2020
1 parent e87d5fa commit 64dfbf4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/development-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

- name: Install python in container
delegate_to: streisand
raw: apt-get install -y python3 python3-apt python3-pip
raw: apt-get update && apt-get install -y python3 python3-apt python3-pip

- name: Set python3 as the default
raw: update-alternatives --install /usr/bin/python python /usr/bin/python3 1
Expand Down
12 changes: 7 additions & 5 deletions util/ansible_check.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash
# shellcheck shell=bash

# Set errexit option to exit immediately on any non-zero status return.
set -e
# This is included by the main streisand script.

# check_ansible checks that Ansible is installed on the local system
# and that it is a supported version.
Expand All @@ -15,10 +14,13 @@ Please see the README Installation section on Prerequisites"
exit 1
fi

if [[ $(ansible --version | grep -oe '2\(.[0-9]\)*') < $REQUIRED_ANSIBLE_VERSION ]]; then
ansible_version="$(ansible --version | head -1 | grep -oe '2[.0-9]*')"

if ! ./util/version_at_least.py "$REQUIRED_ANSIBLE_VERSION" "$ansible_version" ; then
echo "
Streisand requires Ansible version $REQUIRED_ANSIBLE_VERSION or higher.
This system has Ansible $(ansible --version)."
This system has Ansible $ansible_version.
"
exit 1
fi
}
16 changes: 16 additions & 0 deletions util/version_at_least.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python

import sys
from distutils.version import StrictVersion

if len(sys.argv) != 3:
print("Usage: version_at_least minimum_version version_to_check")
sys.exit(1)

minimum_version = StrictVersion(sys.argv[1].strip())
version_to_check = StrictVersion(sys.argv[2].strip())

if version_to_check >= minimum_version:
sys.exit(0)
else:
sys.exit(1)

0 comments on commit 64dfbf4

Please sign in to comment.