summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2018-01-09 16:17:55 -0600
committerGitHub <noreply@github.com>2018-01-09 16:17:55 -0600
commit55352bdda470d23116576226987f90cf2b386244 (patch)
treee45c7f5b3d77cde0fd774a01c8aaa70c7c464c85
parent2f667558498b2bd58ad32ca0b318c85a3c7ff8d4 (diff)
downloadansible-55352bdda470d23116576226987f90cf2b386244.tar.gz
Error early if executing python version doesn't meet documented minimums (#34655)
* Error early if executing python version doesn't meet documented minimums. Fixes #34597 * Make recommended enhancements
-rwxr-xr-xbin/ansible9
-rw-r--r--lib/ansible/module_utils/basic.py12
2 files changed, 21 insertions, 0 deletions
diff --git a/bin/ansible b/bin/ansible
index 3a2f03e64e..c3d9620115 100755
--- a/bin/ansible
+++ b/bin/ansible
@@ -41,6 +41,15 @@ from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
from ansible.module_utils._text import to_text
+# Used for determining if the system is running a new enough python version
+# and should only restrict on our documented minimum versions
+_PY3_MIN = sys.version_info[:2] >= (3, 5)
+_PY2_MIN = (2, 6) <= sys.version_info[:2] < (3,)
+_PY_MIN = _PY3_MIN or _PY2_MIN
+if not _PY_MIN:
+ raise SystemExit('ERROR: Ansible requires a minimum of Python2 version 2.6 or Python3 version 3.5. Current version: %s' % ''.join(sys.version.splitlines()))
+
+
class LastResort(object):
# OUTPUT OF LAST RESORT
def display(self, msg, log_only=None):
diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py
index 47540ee543..c42c753b10 100644
--- a/lib/ansible/module_utils/basic.py
+++ b/lib/ansible/module_utils/basic.py
@@ -232,6 +232,18 @@ PERM_BITS = 0o7777 # file mode permission bits
EXEC_PERM_BITS = 0o0111 # execute permission bits
DEFAULT_PERM = 0o0666 # default file permission bits
+# Used for determining if the system is running a new enough python version
+# and should only restrict on our documented minimum versions
+_PY3_MIN = sys.version_info[:2] >= (3, 5)
+_PY2_MIN = (2, 6) <= sys.version_info[:2] < (3,)
+_PY_MIN = _PY3_MIN or _PY2_MIN
+if not _PY_MIN:
+ print(
+ '\n{"failed": true, '
+ '"msg": "Ansible requires a minimum of Python2 version 2.6 or Python3 version 3.5. Current version: %s"}' % ''.join(sys.version.splitlines())
+ )
+ sys.exit(1)
+
def get_platform():
''' what's the platform? example: Linux is a platform. '''