Skip to content

Commit

Permalink
fixup! ansible_mitogen: Templated connection timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
moreati committed Dec 18, 2024
1 parent 2e9e6a7 commit 19f45bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
24 changes: 21 additions & 3 deletions ansible_mitogen/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,22 +328,40 @@ def run(self, iterator, play_context, result=0):
finally:
ansible_mitogen.process.set_worker_model(None)

def _smuggle_to_connction_reset(self, task, play_context, iterator, target_host):
# Workaround for https://github.com/ansible/ansible/issues/84238
def _smuggle_to_connection_reset(self, task, play_context, iterator, target_host):
"""
Create a templar and make it available for use in Connection.reset().
This allows templated connection variables to be used when Mitogen
reconstructs its connection stack.
"""
variables = self._variable_manager.get_vars(
play=iterator._play, host=target_host, task=task,
_hosts=self._hosts_cache, _hosts_all=self._hosts_cache_all,
)
templar = ansible.template.Templar(
loader=self._loader, variables=variables,
)

# Required for remote_user option set by variable (e.g. ansible_user).
# Without it remote_user in ansible.cfg gets used.
play_context = play_context.set_task_and_variable_override(
task=task, variables=variables, templar=templar,
)
play_context.post_validate(templar=templar)

# Required for timeout option set by variable (e.g. ansible_timeout).
# Without it the task timeout keyword (default: 0) gets used.
play_context.update_vars(variables)

# Stash the task and templar somewhere Connection.reset() can find it
play_context.vars.update({
'_mitogen.smuggled.reset_connection': (task, templar),
})
return play_context

def _execute_meta(self, task, play_context, iterator, target_host):
if task.args['_raw_params'] == 'reset_connection':
self._smuggle_to_connction_reset(task, play_context, iterator, target_host)
play_context = self._smuggle_to_connection_reset(task, play_context, iterator, target_host)

return super(StrategyMixin, self)._execute_meta(
task, play_context, iterator, target_host,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- env.cwd == ansible_user_dir
- (not env.mitogen_loaded) or (env.python_path.count("") == 1)
fail_msg: |
ansible_user_dir={{ ansible_user_dir }}
env={{ env }}
- name: Run some new-style from ansible.module_utils... modules
Expand Down

0 comments on commit 19f45bd

Please sign in to comment.