summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell Teague <rteague@redhat.com>2016-12-07 14:11:23 -0500
committerRussell Teague <rteague@redhat.com>2016-12-08 13:22:37 -0500
commita6aea71d78bb09a2647808405f1f7ade4ca67865 (patch)
treef01219965f3a940eb14efb86774f49219a1225ba
parenteca8a4176b0a85f116d2632289dc62009e2999ab (diff)
downloadopenshift-a6aea71d78bb09a2647808405f1f7ade4ca67865.tar.gz
openshift-a6aea71d78bb09a2647808405f1f7ade4ca67865.tar.bz2
openshift-a6aea71d78bb09a2647808405f1f7ade4ca67865.tar.xz
openshift-a6aea71d78bb09a2647808405f1f7ade4ca67865.zip
Minimum Ansible version check
Moved version check to callback pluging to allow checking the version prior to playbook syntax checking. This prevents errors on syntax-checking with older versions of Ansible.
-rw-r--r--callback_plugins/0_version_requirement.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/callback_plugins/0_version_requirement.py b/callback_plugins/0_version_requirement.py
new file mode 100644
index 000000000..0c9c2cda9
--- /dev/null
+++ b/callback_plugins/0_version_requirement.py
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+
+import sys
+from ansible import __version__
+
+if __version__ < '2.0':
+ from ansible.callbacks import display as pre2_display
+ CallbackBase = object
+
+ def display(*args, **kwargs):
+ pre2_display(*args, **kwargs)
+else:
+ from ansible.plugins.callback import CallbackBase
+ from ansible.utils.display import Display
+
+ def display(*args, **kwargs):
+ display_instance = Display()
+ display_instance.display(*args, **kwargs)
+
+
+# Set to minimum required Ansible version
+required_version = '2.2.0.0'
+DESCRIPTION = "Supported versions: %s or newer" % required_version
+
+
+def version_requirement(version):
+ return version >= required_version
+
+
+class CallbackModule(CallbackBase):
+ """
+ This callback module stops playbook execution if the Ansible
+ version is less than required, defined by required_version
+ """
+
+ CALLBACK_VERSION = 1.0
+ CALLBACK_NAME = 'version_requirement'
+
+ def __init__(self):
+ super(CallbackModule, self).__init__()
+
+ if not version_requirement(__version__):
+ display(
+ 'FATAL: Current Ansible version (%s) is not supported. %s'
+ % (__version__, DESCRIPTION), color='red')
+ sys.exit(1)