From a6aea71d78bb09a2647808405f1f7ade4ca67865 Mon Sep 17 00:00:00 2001 From: Russell Teague Date: Wed, 7 Dec 2016 14:11:23 -0500 Subject: 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. --- callback_plugins/0_version_requirement.py | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 callback_plugins/0_version_requirement.py 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) -- cgit v1.2.3