Skip to content

Commit

Permalink
Error early if executing python version doesn't meet documented minim…
Browse files Browse the repository at this point in the history
…ums (ansible#34655)

* Error early if executing python version doesn't meet documented minimums. Fixes ansible#34597

* Make recommended enhancements
  • Loading branch information
sivel committed Jan 9, 2018
1 parent 2f66755 commit 55352bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bin/ansible
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions lib/ansible/module_utils/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@
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. '''
Expand Down

0 comments on commit 55352bd

Please sign in to comment.