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
pull/35073/head
Jordan Borean 7 years ago committed by GitHub
parent 676ce74cbf
commit 389f4ef1fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -85,6 +85,8 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
tmp = self._connection._shell.tempdir
if task_vars is None: if task_vars is None:
task_vars = dict() task_vars = dict()
@ -146,11 +148,11 @@ class ActionModule(ActionBase):
if self._play_context.diff: if self._play_context.diff:
diff = self._get_diff_data(dest, path, task_vars) 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) xfered = self._transfer_file(path, remote_path)
# fix file permissions when the copy is done as a different user # 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,)) new_module_args.update(dict(src=xfered,))
@ -164,6 +166,6 @@ class ActionModule(ActionBase):
except AnsibleAction as e: except AnsibleAction as e:
result.update(e.result) result.update(e.result)
finally: finally:
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return result return result

@ -15,6 +15,8 @@ class ActionModule(ActionBase):
self._supports_async = True self._supports_async = True
results = super(ActionModule, self).run(tmp, task_vars) 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 # Command module has a special config option to turn off the command nanny warnings
if 'warn' not in self._task.args: if 'warn' not in self._task.args:
self._task.args['warn'] = C.COMMAND_WARNINGS self._task.args['warn'] = C.COMMAND_WARNINGS
@ -24,6 +26,6 @@ class ActionModule(ActionBase):
if not wrap_async: if not wrap_async:
# remove a temporary path we created # remove a temporary path we created
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return results return results

@ -258,7 +258,7 @@ class ActionModule(ActionBase):
return result return result
# Define a remote directory that we will copy the file to. # 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 remote_path = None
@ -273,7 +273,7 @@ class ActionModule(ActionBase):
# fix file permissions when the copy is done as a different user # fix file permissions when the copy is done as a different user
if remote_path: if remote_path:
self._fixup_perms2((self._connection._shell.tempdir, remote_path)) self._fixup_perms2((tmp, remote_path))
if raw: if raw:
# Continue to next iteration if raw is defined. # Continue to next iteration if raw is defined.
@ -389,7 +389,6 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) 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) source = self._task.args.get('src', None)
@ -548,6 +547,6 @@ class ActionModule(ActionBase):
result.update(dict(dest=dest, src=source, changed=changed)) result.update(dict(dest=dest, src=source, changed=changed))
# Delete tmp path # Delete tmp path
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return result return result

@ -44,6 +44,8 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
tmp = self._connection._shell.tempdir
try: try:
if self._play_context.check_mode: if self._play_context.check_mode:
result['skipped'] = True 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)) result.update(dict(changed=False, md5sum=local_md5, file=source, dest=dest, checksum=local_checksum))
finally: finally:
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return result return result

@ -31,6 +31,8 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
tmp = self._connection._shell.tempdir
if not result.get('skipped'): if not result.get('skipped'):
if result.get('invocation', {}).get('module_args'): if result.get('invocation', {}).get('module_args'):
@ -51,6 +53,6 @@ class ActionModule(ActionBase):
if not wrap_async: if not wrap_async:
# remove a temporary path we created # remove a temporary path we created
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return result return result

@ -39,6 +39,8 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
tmp = self._connection._shell.tempdir
module = self._task.args.get('use', 'auto') module = self._task.args.get('use', 'auto')
if module == 'auto': if module == 'auto':
@ -76,6 +78,6 @@ class ActionModule(ActionBase):
finally: finally:
if not self._task.async_val: if not self._task.async_val:
# remove a temporary path we created # remove a temporary path we created
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return result return result

@ -36,6 +36,8 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
tmp = self._connection._shell.tempdir
src = self._task.args.get('src', None) src = self._task.args.get('src', None)
remote_src = boolean(self._task.args.get('remote_src', 'no'), strict=False) remote_src = boolean(self._task.args.get('remote_src', 'no'), strict=False)
@ -52,7 +54,7 @@ class ActionModule(ActionBase):
except AnsibleError as e: except AnsibleError as e:
raise AnsibleActionFail(to_native(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._transfer_file(src, tmp_src)
self._fixup_perms2((tmp_src,)) self._fixup_perms2((tmp_src,))
@ -67,5 +69,5 @@ class ActionModule(ActionBase):
except AnsibleAction as e: except AnsibleAction as e:
result.update(e.result) result.update(e.result)
finally: finally:
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return result return result

@ -42,6 +42,8 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
tmp = self._connection._shell.tempdir
try: try:
creates = self._task.args.get('creates') creates = self._task.args.get('creates')
if creates: if creates:
@ -88,7 +90,7 @@ class ActionModule(ActionBase):
if not self._play_context.check_mode: if not self._play_context.check_mode:
# transfer the file to a remote tmp location # 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 # 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 # 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: except AnsibleAction as e:
result.update(e.result) result.update(e.result)
finally: finally:
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return result return result

@ -38,6 +38,8 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
tmp = self._connection._shell.tempdir
module = self._task.args.get('use', 'auto').lower() module = self._task.args.get('use', 'auto').lower()
if module == 'auto': if module == 'auto':
@ -84,6 +86,6 @@ class ActionModule(ActionBase):
result.update(e.result) result.update(e.result)
finally: finally:
if not self._task.async_val: if not self._task.async_val:
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return result return result

@ -24,7 +24,4 @@ class ActionModule(ActionBase):
shared_loader_obj=self._shared_loader_obj) shared_loader_obj=self._shared_loader_obj)
result = command_action.run(task_vars=task_vars) result = command_action.run(task_vars=task_vars)
# remove a temporary path we created
self._remove_tmp_path(self._connection._shell.tempdir)
return result return result

@ -42,6 +42,8 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
tmp = self._connection._shell.tempdir
source = self._task.args.get('src', None) source = self._task.args.get('src', None)
dest = self._task.args.get('dest', None) dest = self._task.args.get('dest', None)
force = boolean(self._task.args.get('force', True), strict=False) force = boolean(self._task.args.get('force', True), strict=False)
@ -152,12 +154,12 @@ class ActionModule(ActionBase):
loader=self._loader, loader=self._loader,
templar=self._templar, templar=self._templar,
shared_loader_obj=self._shared_loader_obj) 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: finally:
shutil.rmtree(tempdir) shutil.rmtree(tempdir)
except AnsibleAction as e: except AnsibleAction as e:
result.update(e.result) result.update(e.result)
finally: finally:
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return result return result

@ -37,6 +37,8 @@ class ActionModule(ActionBase):
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)
tmp = self._connection._shell.tempdir
source = self._task.args.get('src', None) source = self._task.args.get('src', None)
dest = self._task.args.get('dest', None) dest = self._task.args.get('dest', None)
remote_src = boolean(self._task.args.get('remote_src', False), strict=False) remote_src = boolean(self._task.args.get('remote_src', False), strict=False)
@ -83,7 +85,7 @@ class ActionModule(ActionBase):
if not remote_src: if not remote_src:
# transfer the file to a remote tmp location # 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) self._transfer_file(source, tmp_src)
# handle diff mode client side # handle diff mode client side
@ -91,7 +93,7 @@ class ActionModule(ActionBase):
if not remote_src: if not remote_src:
# fix file permissions when the copy is done as a different user # 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. # Build temporary module_args.
new_module_args = self._task.args.copy() new_module_args = self._task.args.copy()
new_module_args.update( new_module_args.update(
@ -119,5 +121,5 @@ class ActionModule(ActionBase):
except AnsibleAction as e: except AnsibleAction as e:
result.update(e.result) result.update(e.result)
finally: finally:
self._remove_tmp_path(self._connection._shell.tempdir) self._remove_tmp_path(tmp)
return result return result

Loading…
Cancel
Save