From 48a0938d04bf30e40df56f3914876c740369c406 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 5 Apr 2018 17:27:02 +0100 Subject: [PATCH] issue #164: add action module to return active strategy. --- tests/ansible/ansible.cfg | 1 + .../ansible/lib/action/determine_strategy.py | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/ansible/lib/action/determine_strategy.py diff --git a/tests/ansible/ansible.cfg b/tests/ansible/ansible.cfg index 7f6524e8..e41b2ba0 100644 --- a/tests/ansible/ansible.cfg +++ b/tests/ansible/ansible.cfg @@ -2,6 +2,7 @@ inventory = hosts gathering = explicit strategy_plugins = ../../ansible_mitogen/plugins/strategy +action_plugins = lib/action library = lib/modules retry_files_enabled = False forks = 50 diff --git a/tests/ansible/lib/action/determine_strategy.py b/tests/ansible/lib/action/determine_strategy.py new file mode 100644 index 00000000..b4b067c1 --- /dev/null +++ b/tests/ansible/lib/action/determine_strategy.py @@ -0,0 +1,25 @@ + +import sys + +from ansible.plugins.strategy import StrategyBase +from ansible.plugins.action import ActionBase + + +class ActionModule(ActionBase): + def _get_strategy_name(self): + frame = sys._getframe() + while frame: + st = frame.f_locals.get('self') + if isinstance(st, StrategyBase): + return '%s.%s' % (type(st).__module__, type(st).__name__) + frame = frame.f_back + return '' + + def run(self, tmp=None, task_vars=None): + return { + 'changed': False, + 'ansible_facts': { + 'strategy': self._get_strategy_name(), + 'is_mitogen': 'ansible_mitogen' in self._get_strategy_name(), + } + }