Ensure action plugins remove tmp dirs created (#15501)

fixes #14917
This commit is contained in:
Brian Coca 2016-04-20 13:39:12 -04:00
parent 67e6bd18e4
commit a5d79a39d5
8 changed files with 29 additions and 18 deletions

View file

@ -42,6 +42,7 @@ class ActionModule(ActionBase):
remote_user = task_vars.get('ansible_ssh_user') or self._play_context.remote_user
if not tmp:
tmp = self._make_tmp_path(remote_user)
self._cleanup_remote_tmp = True
creates = self._task.args.get('creates')
if creates:
@ -49,6 +50,7 @@ class ActionModule(ActionBase):
# and the filename already exists. This allows idempotence
# of command executions.
if self._remote_file_exists(creates):
self._remove_tmp_path(tmp)
return dict(skipped=True, msg=("skipped, since %s exists" % creates))
removes = self._task.args.get('removes')
@ -57,6 +59,7 @@ class ActionModule(ActionBase):
# and the filename does not exist. This allows idempotence
# of command executions.
if not self._remote_file_exists(removes):
self._remove_tmp_path(tmp)
return dict(skipped=True, msg=("skipped, since %s does not exist" % removes))
# the script name is the first item in the raw params, so we split it
@ -87,8 +90,7 @@ class ActionModule(ActionBase):
result.update(self._low_level_execute_command(cmd=script_cmd, sudoable=True))
# clean up after
if tmp and "tmp" in tmp and not C.DEFAULT_KEEP_REMOTE_FILES:
self._remove_tmp_path(tmp)
self._remove_tmp_path(tmp)
result['changed'] = True