summaryrefslogtreecommitdiffstats
path: root/roles/lib_utils/callback_plugins/aa_version_requirement.py
diff options
context:
space:
mode:
authorMichael Gugino <mgugino@redhat.com>2017-12-13 12:42:32 -0500
committerMichael Gugino <mgugino@redhat.com>2017-12-18 16:46:22 -0500
commit801779eeb6f6308f81ae7c48409de7686c04a0aa (patch)
treeb6e4e6fcf8b672f5c5ed1269e7ed0c93258090f3 /roles/lib_utils/callback_plugins/aa_version_requirement.py
parent84266ade6839f9a82e3111f12fce64b88a48845a (diff)
downloadopenshift-801779eeb6f6308f81ae7c48409de7686c04a0aa.tar.gz
openshift-801779eeb6f6308f81ae7c48409de7686c04a0aa.tar.bz2
openshift-801779eeb6f6308f81ae7c48409de7686c04a0aa.tar.xz
openshift-801779eeb6f6308f81ae7c48409de7686c04a0aa.zip
Relocate filter plugins to lib_utils
This commit relocates filter_plugings to lib_utils, changes the namespacing to prevent unintended use of older versions that may be present in filter_plugins/ directory on existing installs. Add lib_utils to meta depends for roles Also consolidate some plugins into lib_utils from various other areas. Update rpm spec, obsolete plugin rpms.
Diffstat (limited to 'roles/lib_utils/callback_plugins/aa_version_requirement.py')
-rw-r--r--roles/lib_utils/callback_plugins/aa_version_requirement.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/roles/lib_utils/callback_plugins/aa_version_requirement.py b/roles/lib_utils/callback_plugins/aa_version_requirement.py
new file mode 100644
index 000000000..1093acdae
--- /dev/null
+++ b/roles/lib_utils/callback_plugins/aa_version_requirement.py
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+
+"""
+This callback plugin verifies the required minimum version of Ansible
+is installed for proper operation of the OpenShift Ansible Installer.
+The plugin is named with leading `aa_` to ensure this plugin is loaded
+first (alphanumerically) by Ansible.
+"""
+import sys
+from ansible import __version__
+
+if __version__ < '2.0':
+ # pylint: disable=import-error,no-name-in-module
+ # Disabled because pylint warns when Ansible v2 is installed
+ from ansible.callbacks import display as pre2_display
+ CallbackBase = object
+
+ def display(*args, **kwargs):
+ """Set up display function for pre Ansible v2"""
+ pre2_display(*args, **kwargs)
+else:
+ from ansible.plugins.callback import CallbackBase
+ from ansible.utils.display import Display
+
+ def display(*args, **kwargs):
+ """Set up display function for Ansible v2"""
+ display_instance = Display()
+ display_instance.display(*args, **kwargs)
+
+
+# Set to minimum required Ansible version
+REQUIRED_VERSION = '2.4.1.0'
+DESCRIPTION = "Supported versions: %s or newer" % REQUIRED_VERSION
+
+
+def version_requirement(version):
+ """Test for minimum required version"""
+ return version >= REQUIRED_VERSION
+
+
+class CallbackModule(CallbackBase):
+ """
+ Ansible callback plugin
+ """
+
+ CALLBACK_VERSION = 1.0
+ CALLBACK_NAME = 'version_requirement'
+
+ def __init__(self):
+ """
+ Version verification is performed in __init__ to catch the
+ requirement early in the execution of Ansible and fail gracefully
+ """
+ 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)