From 6309774be26e00f59823937bef5d1ffc2cd9e07f Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 6 Mar 2019 12:06:55 +0000 Subject: [PATCH] issue #554: fix Ansible 2.4 compatibility --- ansible_mitogen/mixins.py | 10 +++++++++- ansible_mitogen/target.py | 8 -------- tests/ansible/integration/action/remove_tmp_path.yml | 3 --- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/ansible_mitogen/mixins.py b/ansible_mitogen/mixins.py index 6aa020fb..890467fd 100644 --- a/ansible_mitogen/mixins.py +++ b/ansible_mitogen/mixins.py @@ -354,7 +354,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase): self._temp_file_gibberish(module_args, wrap_async) self._connection._connect() - return ansible_mitogen.planner.invoke( + result = ansible_mitogen.planner.invoke( ansible_mitogen.planner.Invocation( action=self, connection=self._connection, @@ -368,6 +368,14 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase): ) ) + if ansible.__version__ < '2.5' and delete_remote_tmp and \ + getattr(self._connection._shell, 'tmpdir', None) is not None: + # Built-in actions expected tmpdir to be cleaned up automatically + # on _execute_module(). + self._remove_tmp_path(self._connection._shell.tmpdir) + + return result + def _postprocess_response(self, result): """ Apply fixups mimicking ActionBase._execute_module(); this is copied diff --git a/ansible_mitogen/target.py b/ansible_mitogen/target.py index 809165da..40e5c57b 100644 --- a/ansible_mitogen/target.py +++ b/ansible_mitogen/target.py @@ -260,14 +260,6 @@ def prune_tree(path): LOG.error('prune_tree(%r): %s', path, e) -def _on_broker_shutdown(): - """ - Respond to broker shutdown (graceful termination by parent, or loss of - connection to parent) by deleting our sole temporary directory. - """ - prune_tree(temp_dir) - - def is_good_temp_dir(path): """ Return :data:`True` if `path` can be used as a temporary directory, logging diff --git a/tests/ansible/integration/action/remove_tmp_path.yml b/tests/ansible/integration/action/remove_tmp_path.yml index 566e4f3f..7a0c6c25 100644 --- a/tests/ansible/integration/action/remove_tmp_path.yml +++ b/tests/ansible/integration/action/remove_tmp_path.yml @@ -6,9 +6,6 @@ hosts: test-targets any_errors_fatal: true tasks: - - meta: end_play - when: not is_mitogen - # # Use the copy module to cause a temporary directory to be created, and # return a result with a 'src' attribute pointing into that directory.