|
37 | 37 | import ansible_mitogen.mixins |
38 | 38 | import ansible_mitogen.process |
39 | 39 |
|
| 40 | +import ansible |
40 | 41 | import ansible.executor.process.worker |
41 | 42 |
|
42 | 43 |
|
| 44 | +ANSIBLE_VERSION_MIN = '2.3' |
| 45 | +ANSIBLE_VERSION_MAX = '2.7' |
| 46 | +NEW_VERSION_MSG = ( |
| 47 | + "Your Ansible version (%s) is too recent. The most recent version\n" |
| 48 | + "supported by Mitogen for Ansible is %s.x. Please check the Mitogen\n" |
| 49 | + "release notes to see if a new version is available, otherwise\n" |
| 50 | + "subscribe to the corresponding GitHub issue to be notified when\n" |
| 51 | + "support becomes available.\n" |
| 52 | + "\n" |
| 53 | + " https://mitogen.rtfd.io/en/latest/changelog.html\n" |
| 54 | + " https://github.com/dw/mitogen/issues/\n" |
| 55 | +) |
| 56 | +OLD_VERSION_MSG = ( |
| 57 | + "Your version of Ansible (%s) is too old. The oldest version supported by " |
| 58 | + "Mitogen for Ansible is %s." |
| 59 | +) |
| 60 | + |
| 61 | + |
| 62 | +def _assert_supported_release(): |
| 63 | + """ |
| 64 | + Throw AnsibleError with a descriptive message in case of being loaded into |
| 65 | + an unsupported Ansible release. |
| 66 | + """ |
| 67 | + v = ansible.__version__ |
| 68 | + |
| 69 | + if v[:len(ANSIBLE_VERSION_MIN)] < ANSIBLE_VERSION_MIN: |
| 70 | + raise ansible.errors.AnsibleError( |
| 71 | + OLD_VERSION_MSG % (v, ANSIBLE_VERSION_MIN) |
| 72 | + ) |
| 73 | + |
| 74 | + if v[:len(ANSIBLE_VERSION_MAX)] > ANSIBLE_VERSION_MAX: |
| 75 | + raise ansible.errors.AnsibleError( |
| 76 | + NEW_VERSION_MSG % (ansible.__version__, ANSIBLE_VERSION_MAX) |
| 77 | + ) |
| 78 | + |
| 79 | + |
43 | 80 | def _patch_awx_callback(): |
44 | 81 | """ |
45 | 82 | issue #400: AWX loads a display callback that suffers from thread-safety |
@@ -245,6 +282,8 @@ def run(self, iterator, play_context, result=0): |
245 | 282 | Arrange for a mitogen.master.Router to be available for the duration of |
246 | 283 | the strategy's real run() method. |
247 | 284 | """ |
| 285 | + _assert_supported_release() |
| 286 | + |
248 | 287 | ansible_mitogen.process.MuxProcess.start() |
249 | 288 | run = super(StrategyMixin, self).run |
250 | 289 | self._add_plugin_paths() |
|
0 commit comments