From 6e039352803f96576bf91a2086986c7a2daad99f Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 19 May 2019 13:12:41 +0100 Subject: [PATCH 1/2] issue #587: ansible: descriptive version check during startup. --- ansible_mitogen/strategy.py | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ansible_mitogen/strategy.py b/ansible_mitogen/strategy.py index ba0ff5251..b9211fcc0 100644 --- a/ansible_mitogen/strategy.py +++ b/ansible_mitogen/strategy.py @@ -37,9 +37,46 @@ import ansible_mitogen.mixins import ansible_mitogen.process +import ansible import ansible.executor.process.worker +ANSIBLE_VERSION_MIN = '2.3' +ANSIBLE_VERSION_MAX = '2.7' +NEW_VERSION_MSG = ( + "Your Ansible version (%s) is too recent. The most recent version\n" + "supported by Mitogen for Ansible is %s.x. Please check the Mitogen\n" + "release notes to see if a new version is available, otherwise\n" + "subscribe to the corresponding GitHub issue to be notified when\n" + "support becomes available.\n" + "\n" + " https://mitogen.rtfd.io/en/latest/changelog.html\n" + " https://github.com/dw/mitogen/issues/\n" +) +OLD_VERSION_MSG = ( + "Your version of Ansible (%s) is too old. The oldest version supported by " + "Mitogen for Ansible is %s." +) + + +def _assert_supported_release(): + """ + Throw AnsibleError with a descriptive message in case of being loaded into + an unsupported Ansible release. + """ + v = ansible.__version__ + + if v[:len(ANSIBLE_VERSION_MIN)] < ANSIBLE_VERSION_MIN: + raise ansible.errors.AnsibleError( + OLD_VERSION_MSG % (v, ANSIBLE_VERSION_MIN) + ) + + if v[:len(ANSIBLE_VERSION_MAX)] > ANSIBLE_VERSION_MAX: + raise ansible.errors.AnsibleError( + NEW_VERSION_MSG % (ansible.__version__, ANSIBLE_VERSION_MAX) + ) + + def _patch_awx_callback(): """ issue #400: AWX loads a display callback that suffers from thread-safety @@ -245,6 +282,8 @@ def run(self, iterator, play_context, result=0): Arrange for a mitogen.master.Router to be available for the duration of the strategy's real run() method. """ + _assert_supported_release() + ansible_mitogen.process.MuxProcess.start() run = super(StrategyMixin, self).run self._add_plugin_paths() From 0b110305c9fa16e2416aecf3abed09a0104e3dcf Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 19 May 2019 13:20:24 +0100 Subject: [PATCH 2/2] issue #587: update Changelog --- docs/changelog.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index e8ee19b42..c09533855 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -44,6 +44,10 @@ Fixes the username, hostname and process ID of ``ansible-playbook`` running on the controller machine. +* `#587 `_: display a friendly + message when running on an unsupported version of Ansible, to cope with + potential influx of 2.8-related bug reports. + Thanks! ~~~~~~~