From 9947e539f36a0be38b4902b7b55f2fc4023a064f Mon Sep 17 00:00:00 2001 From: Russell Teague Date: Fri, 9 Dec 2016 08:27:05 -0500 Subject: Resolved lint issues --- callback_plugins/0_version_requirement.py | 46 ----------------------- callback_plugins/aa_version_requirement.py | 60 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 46 deletions(-) delete mode 100644 callback_plugins/0_version_requirement.py create mode 100644 callback_plugins/aa_version_requirement.py diff --git a/callback_plugins/0_version_requirement.py b/callback_plugins/0_version_requirement.py deleted file mode 100644 index 0c9c2cda9..000000000 --- a/callback_plugins/0_version_requirement.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/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) diff --git a/callback_plugins/aa_version_requirement.py b/callback_plugins/aa_version_requirement.py new file mode 100644 index 000000000..1cca19a45 --- /dev/null +++ b/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.2.0.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) -- cgit v1.2.3