Repository: ansible/ansible

Issue:
Ansible py3 > 3.4 should be coded as a requirement
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Bug Report

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
$ ansible --version
ERROR! Unexpected Exception, this is probably a bug: unsupported operand type(s) for %: 'bytes' and 'bytes'
the full traceback was:

Traceback (most recent call last):
  File "/home/bdowling/py34/bin/ansible", line 88, in <module>
    mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
  File "/home/bdowling/py34/lib/python3.4/site-packages/ansible/cli/__init__.py", line 38, in <module>
    from ansible.inventory.manager import InventoryManager
  File "/home/bdowling/py34/lib/python3.4/site-packages/ansible/inventory/manager.py", line 44, in <module>
    IGNORED_EXTS = [b'%s$' % to_bytes(re.escape(x)) for x in C.INVENTORY_IGNORE_EXTS]
  File "/home/bdowling/py34/lib/python3.4/site-packages/ansible/inventory/manager.py", line 44, in <listcomp>
    IGNORED_EXTS = [b'%s$' % to_bytes(re.escape(x)) for x in C.INVENTORY_IGNORE_EXTS]
TypeError: unsupported operand type(s) for %: 'bytes' and 'bytes'

(py34) [bdowling@bdvm:~]
$ python --version
Python 3.4.6
```
##### SUMMARY
<!--- Explain the problem briefly -->

If python3.5+ is required, shouldn't there be a test or complain early about this rather than producing obscure errors when it is installed in py3 < 3.4?  Seems this has bitten a few people over time.  It is *documented* but a test would nice.

Re #31623, #24180, #33619, #23680, #25547, etc.
Docs were fix mentioned in #25548



Discussion:
@bdowling Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. 

Here are the items we could not find in your description:
- component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->

Resolving patch:
diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py
--- a/lib/ansible/module_utils/basic.py
+++ b/lib/ansible/module_utils/basic.py
@@ -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. '''


Test patch: