@@ -933,31 +933,39 @@ def reset(self):
933933 self .reset_compat_msg
934934 )
935935
936- # Strategy's _execute_meta doesn't have an action obj but we'll need one for
937- # running interpreter_discovery
938- # will create a new temporary action obj for this purpose
939- self ._action = ansible_mitogen .mixins .ActionModuleMixin (
940- task = 0 ,
941- connection = self ,
942- play_context = self ._play_context ,
943- loader = 0 ,
944- templar = 0 ,
945- shared_loader_obj = 0
946- )
947-
948- # Workaround for https://github.com/ansible/ansible/issues/84238
936+ # Handle templated connection variables during `meta: reset_connection`.
937+ # Many bugs/implementation details of Mitogen & Ansible collide here.
938+ # See #1079, #1096, #1132, ansible/ansible#84238, ...
949939 try :
950940 task , templar = self ._play_context .vars .pop (
951941 '_mitogen.smuggled.reset_connection' ,
952942 )
953943 except KeyError :
954- pass
944+ self . _action_monkey_patched_by_mitogen = False
955945 else :
946+ # LOG.info('%r.reset(): remote_addr=%r', self, self._play_context.remote_addr)
947+ # ansible.plugins.strategy.StrategyBase._execute_meta() doesn't
948+ # have an action object, which we need for interpreter_discovery.
949+ # Create a temporary action object for this purpose.
950+ self ._action = ansible_mitogen .mixins .ActionModuleMixin (
951+ task = task ,
952+ connection = self ,
953+ play_context = self ._play_context ,
954+ loader = templar ._loader ,
955+ templar = templar ,
956+ shared_loader_obj = 0 ,
957+ )
958+ self ._action_monkey_patched_by_mitogen = True
959+
960+ # Workaround for https://github.com/ansible/ansible/issues/84238
956961 self .set_options (
957962 task_keys = task .dump_attrs (),
958963 var_options = self ._mitogen_var_options (templar ),
959964 )
960965
966+ del task
967+ del templar
968+
961969 # Clear out state in case we were ever connected.
962970 self .close ()
963971
@@ -977,6 +985,11 @@ def reset(self):
977985 finally :
978986 binding .close ()
979987
988+ # Cleanup any monkey patching we did for `meta: reset_connection`
989+ if self ._action_monkey_patched_by_mitogen :
990+ del self ._action
991+ del self ._action_monkey_patched_by_mitogen
992+
980993 # Compatibility with Ansible 2.4 wait_for_connection plug-in.
981994 _reset = reset
982995
0 commit comments