summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2019-12-06 16:29:26 -0600
committerMatt Clay <matt@mystile.com>2020-01-10 18:29:29 -0800
commit09e89d538cdd7ac20bae4df6c8247e5562415453 (patch)
tree9801db4382420874dc25fd8c294b8b2a3704c5ca /lib
parent56c6ebe2582090ee98f0468f1b9d26dcfbf23f84 (diff)
downloadansible-09e89d538cdd7ac20bae4df6c8247e5562415453.tar.gz
[stable-2.9] Add method to automatically clean up after an action plugin (#65509)
* Use correct var, move cleanup for async * Add changelog and tests. Fixes #65393. Fixes #65277. * Kill off all long running async tasks from listen_ports_facts * Update task to work with older jinja2 (cherry picked from commit 03a4edb) Co-authored-by: Matt Martz <matt@sivel.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/executor/task_executor.py3
-rw-r--r--lib/ansible/plugins/action/__init__.py12
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
index 36ff939e94..07f250af63 100644
--- a/lib/ansible/executor/task_executor.py
+++ b/lib/ansible/executor/task_executor.py
@@ -649,6 +649,8 @@ class TaskExecutor:
return dict(failed=True, msg=to_text(e))
except AnsibleConnectionFailure as e:
return dict(unreachable=True, msg=to_text(e))
+ finally:
+ self._handler.cleanup()
display.debug("handler run complete")
# preserve no log
@@ -853,6 +855,7 @@ class TaskExecutor:
else:
return dict(failed=True, msg="async task produced unparseable results", async_result=async_result)
else:
+ async_handler.cleanup(force=True)
return async_result
def _get_become(self, name):
diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py
index 8b70d46cff..dc72e6c56c 100644
--- a/lib/ansible/plugins/action/__init__.py
+++ b/lib/ansible/plugins/action/__init__.py
@@ -115,6 +115,18 @@ class ActionBase(with_metaclass(ABCMeta, object)):
return result
+ def cleanup(self, force=False):
+ """Method to perform a clean up at the end of an action plugin execution
+
+ By default this is designed to clean up the shell tmpdir, and is toggled based on whether
+ async is in use
+
+ Action plugins may override this if they deem necessary, but should still call this method
+ via super
+ """
+ if force or not self._task.async_val:
+ self._remove_tmp_path(self._connection._shell.tmpdir)
+
def get_plugin_option(self, plugin, option, default=None):
"""Helper to get an option from a plugin without having to use
the try/except dance everywhere to set a default