From 19ba2417c8262c10fbeee57476738d3a3f1ba5dc Mon Sep 17 00:00:00 2001 From: Steven Robertson Date: Fri, 31 Jan 2020 15:14:44 -0800 Subject: [PATCH] now able to get the action object, but recursion error in low_level_exec_command --- ansible_mitogen/connection.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index 411b2d88..8f7dd735 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -551,6 +551,26 @@ class Connection(ansible.plugins.connection.ConnectionBase): connection passed into any running action. """ if self._task_vars is not None: + # check for if self._action has already been set or not + # there are some cases where the ansible executor passes in task_vars + # so we don't walk the stack to find them + # TODO: is there a better way to get the ActionModuleMixin object? + # ansible python discovery needs it to run discover_interpreter() + if not hasattr(self, '_action'): + f = sys._getframe() + while f: + if f.f_code.co_name == 'run': + f_self = f.f_locals.get('self') + if isinstance(f_self, ansible_mitogen.mixins.ActionModuleMixin): + self._action = f_self + break + elif f.f_code.co_name == '_execute_meta': + f_self = f.f_locals.get('self') + if isinstance(f_self, ansible_mitogen.mixins.ActionModuleMixin): + self._action = f_self + break + f = f.f_back + return self._task_vars f = sys._getframe()