From 389f4ef1fb71629a3389306e6324ea5b118275ff Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Fri, 19 Jan 2018 09:51:42 +1000 Subject: [PATCH] template: change to pass along the correct template path (#35027) * template: change to pass along the correct template path * standardise tmp path behaviour * removed if condition as it should not be needed --- lib/ansible/plugins/action/assemble.py | 8 +++++--- lib/ansible/plugins/action/command.py | 4 +++- lib/ansible/plugins/action/copy.py | 9 ++++----- lib/ansible/plugins/action/fetch.py | 4 +++- lib/ansible/plugins/action/normal.py | 4 +++- lib/ansible/plugins/action/package.py | 4 +++- lib/ansible/plugins/action/patch.py | 6 ++++-- lib/ansible/plugins/action/script.py | 6 ++++-- lib/ansible/plugins/action/service.py | 4 +++- lib/ansible/plugins/action/shell.py | 3 --- lib/ansible/plugins/action/template.py | 6 ++++-- lib/ansible/plugins/action/unarchive.py | 8 +++++--- 12 files changed, 41 insertions(+), 25 deletions(-) diff --git a/lib/ansible/plugins/action/assemble.py b/lib/ansible/plugins/action/assemble.py index 41cd32fa8a1..9ce105b50f2 100644 --- a/lib/ansible/plugins/action/assemble.py +++ b/lib/ansible/plugins/action/assemble.py @@ -85,6 +85,8 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) + tmp = self._connection._shell.tempdir + if task_vars is None: task_vars = dict() @@ -146,11 +148,11 @@ class ActionModule(ActionBase): if self._play_context.diff: diff = self._get_diff_data(dest, path, task_vars) - remote_path = self._connection._shell.join_path(self._connection._shell.tempdir, 'src') + remote_path = self._connection._shell.join_path(tmp, 'src') xfered = self._transfer_file(path, remote_path) # fix file permissions when the copy is done as a different user - self._fixup_perms2((self._connection._shell.tempdir, remote_path)) + self._fixup_perms2((tmp, remote_path)) new_module_args.update(dict(src=xfered,)) @@ -164,6 +166,6 @@ class ActionModule(ActionBase): except AnsibleAction as e: result.update(e.result) finally: - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return result diff --git a/lib/ansible/plugins/action/command.py b/lib/ansible/plugins/action/command.py index 455480a4dd8..63a52a0e2eb 100644 --- a/lib/ansible/plugins/action/command.py +++ b/lib/ansible/plugins/action/command.py @@ -15,6 +15,8 @@ class ActionModule(ActionBase): self._supports_async = True results = super(ActionModule, self).run(tmp, task_vars) + tmp = self._connection._shell.tempdir + # Command module has a special config option to turn off the command nanny warnings if 'warn' not in self._task.args: self._task.args['warn'] = C.COMMAND_WARNINGS @@ -24,6 +26,6 @@ class ActionModule(ActionBase): if not wrap_async: # remove a temporary path we created - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return results diff --git a/lib/ansible/plugins/action/copy.py b/lib/ansible/plugins/action/copy.py index 0960b0972db..45b639b5ace 100644 --- a/lib/ansible/plugins/action/copy.py +++ b/lib/ansible/plugins/action/copy.py @@ -258,7 +258,7 @@ class ActionModule(ActionBase): return result # Define a remote directory that we will copy the file to. - tmp_src = self._connection._shell.join_path(self._connection._shell.tempdir, 'source') + tmp_src = self._connection._shell.join_path(tmp, 'source') remote_path = None @@ -273,7 +273,7 @@ class ActionModule(ActionBase): # fix file permissions when the copy is done as a different user if remote_path: - self._fixup_perms2((self._connection._shell.tempdir, remote_path)) + self._fixup_perms2((tmp, remote_path)) if raw: # Continue to next iteration if raw is defined. @@ -389,8 +389,7 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) - if tmp is None: - tmp = self._connection._shell.tempdir + tmp = self._connection._shell.tempdir source = self._task.args.get('src', None) content = self._task.args.get('content', None) @@ -548,6 +547,6 @@ class ActionModule(ActionBase): result.update(dict(dest=dest, src=source, changed=changed)) # Delete tmp path - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return result diff --git a/lib/ansible/plugins/action/fetch.py b/lib/ansible/plugins/action/fetch.py index 24881eb0aa2..f87c0b55359 100644 --- a/lib/ansible/plugins/action/fetch.py +++ b/lib/ansible/plugins/action/fetch.py @@ -44,6 +44,8 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) + tmp = self._connection._shell.tempdir + try: if self._play_context.check_mode: result['skipped'] = True @@ -212,6 +214,6 @@ class ActionModule(ActionBase): result.update(dict(changed=False, md5sum=local_md5, file=source, dest=dest, checksum=local_checksum)) finally: - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return result diff --git a/lib/ansible/plugins/action/normal.py b/lib/ansible/plugins/action/normal.py index 221c2982438..ad2c04bd50e 100644 --- a/lib/ansible/plugins/action/normal.py +++ b/lib/ansible/plugins/action/normal.py @@ -31,6 +31,8 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) + tmp = self._connection._shell.tempdir + if not result.get('skipped'): if result.get('invocation', {}).get('module_args'): @@ -51,6 +53,6 @@ class ActionModule(ActionBase): if not wrap_async: # remove a temporary path we created - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return result diff --git a/lib/ansible/plugins/action/package.py b/lib/ansible/plugins/action/package.py index f01176f5dd7..54a9d9737c9 100644 --- a/lib/ansible/plugins/action/package.py +++ b/lib/ansible/plugins/action/package.py @@ -39,6 +39,8 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) + tmp = self._connection._shell.tempdir + module = self._task.args.get('use', 'auto') if module == 'auto': @@ -76,6 +78,6 @@ class ActionModule(ActionBase): finally: if not self._task.async_val: # remove a temporary path we created - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return result diff --git a/lib/ansible/plugins/action/patch.py b/lib/ansible/plugins/action/patch.py index a54548c9a64..7002b40edd1 100644 --- a/lib/ansible/plugins/action/patch.py +++ b/lib/ansible/plugins/action/patch.py @@ -36,6 +36,8 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) + tmp = self._connection._shell.tempdir + src = self._task.args.get('src', None) remote_src = boolean(self._task.args.get('remote_src', 'no'), strict=False) @@ -52,7 +54,7 @@ class ActionModule(ActionBase): except AnsibleError as e: raise AnsibleActionFail(to_native(e)) - tmp_src = self._connection._shell.join_path(self._connection._shell.tempdir, os.path.basename(src)) + tmp_src = self._connection._shell.join_path(tmp, os.path.basename(src)) self._transfer_file(src, tmp_src) self._fixup_perms2((tmp_src,)) @@ -67,5 +69,5 @@ class ActionModule(ActionBase): except AnsibleAction as e: result.update(e.result) finally: - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return result diff --git a/lib/ansible/plugins/action/script.py b/lib/ansible/plugins/action/script.py index ddf7a279767..b1a43cfbdaa 100644 --- a/lib/ansible/plugins/action/script.py +++ b/lib/ansible/plugins/action/script.py @@ -42,6 +42,8 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) + tmp = self._connection._shell.tempdir + try: creates = self._task.args.get('creates') if creates: @@ -88,7 +90,7 @@ class ActionModule(ActionBase): if not self._play_context.check_mode: # transfer the file to a remote tmp location - tmp_src = self._connection._shell.join_path(self._connection._shell.tempdir, os.path.basename(source)) + tmp_src = self._connection._shell.join_path(tmp, os.path.basename(source)) # Convert raw_params to text for the purpose of replacing the script since # parts and tmp_src are both unicode strings and raw_params will be different @@ -132,6 +134,6 @@ class ActionModule(ActionBase): except AnsibleAction as e: result.update(e.result) finally: - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return result diff --git a/lib/ansible/plugins/action/service.py b/lib/ansible/plugins/action/service.py index 5291a889b3a..bdf4d32dbc8 100644 --- a/lib/ansible/plugins/action/service.py +++ b/lib/ansible/plugins/action/service.py @@ -38,6 +38,8 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) + tmp = self._connection._shell.tempdir + module = self._task.args.get('use', 'auto').lower() if module == 'auto': @@ -84,6 +86,6 @@ class ActionModule(ActionBase): result.update(e.result) finally: if not self._task.async_val: - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return result diff --git a/lib/ansible/plugins/action/shell.py b/lib/ansible/plugins/action/shell.py index 8aedd05060d..da0385824bc 100644 --- a/lib/ansible/plugins/action/shell.py +++ b/lib/ansible/plugins/action/shell.py @@ -24,7 +24,4 @@ class ActionModule(ActionBase): shared_loader_obj=self._shared_loader_obj) result = command_action.run(task_vars=task_vars) - # remove a temporary path we created - self._remove_tmp_path(self._connection._shell.tempdir) - return result diff --git a/lib/ansible/plugins/action/template.py b/lib/ansible/plugins/action/template.py index 2be1a61ceed..9b2044215f5 100644 --- a/lib/ansible/plugins/action/template.py +++ b/lib/ansible/plugins/action/template.py @@ -42,6 +42,8 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) + tmp = self._connection._shell.tempdir + source = self._task.args.get('src', None) dest = self._task.args.get('dest', None) force = boolean(self._task.args.get('force', True), strict=False) @@ -152,12 +154,12 @@ class ActionModule(ActionBase): loader=self._loader, templar=self._templar, shared_loader_obj=self._shared_loader_obj) - result.update(copy_action.run(task_vars=task_vars)) + result.update(copy_action.run(task_vars=task_vars, tmp=tmp)) finally: shutil.rmtree(tempdir) except AnsibleAction as e: result.update(e.result) finally: - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return result diff --git a/lib/ansible/plugins/action/unarchive.py b/lib/ansible/plugins/action/unarchive.py index 7b244c1ec44..fdcb59aef9d 100644 --- a/lib/ansible/plugins/action/unarchive.py +++ b/lib/ansible/plugins/action/unarchive.py @@ -37,6 +37,8 @@ class ActionModule(ActionBase): result = super(ActionModule, self).run(tmp, task_vars) + tmp = self._connection._shell.tempdir + source = self._task.args.get('src', None) dest = self._task.args.get('dest', None) remote_src = boolean(self._task.args.get('remote_src', False), strict=False) @@ -83,7 +85,7 @@ class ActionModule(ActionBase): if not remote_src: # transfer the file to a remote tmp location - tmp_src = self._connection._shell.join_path(self._connection._shell.tempdir, 'source') + tmp_src = self._connection._shell.join_path(tmp, 'source') self._transfer_file(source, tmp_src) # handle diff mode client side @@ -91,7 +93,7 @@ class ActionModule(ActionBase): if not remote_src: # fix file permissions when the copy is done as a different user - self._fixup_perms2((self._connection._shell.tempdir, tmp_src)) + self._fixup_perms2((tmp, tmp_src)) # Build temporary module_args. new_module_args = self._task.args.copy() new_module_args.update( @@ -119,5 +121,5 @@ class ActionModule(ActionBase): except AnsibleAction as e: result.update(e.result) finally: - self._remove_tmp_path(self._connection._shell.tempdir) + self._remove_tmp_path(tmp) return result