|
|
|
|
@ -125,40 +125,44 @@ class ActionModule(ActionBase):
|
|
|
|
|
return remote_checksum
|
|
|
|
|
|
|
|
|
|
if local_checksum != remote_checksum:
|
|
|
|
|
# if showing diffs, we need to get the remote value
|
|
|
|
|
dest_contents = ''
|
|
|
|
|
|
|
|
|
|
# FIXME: still need to implement diff mechanism
|
|
|
|
|
#if self.runner.diff:
|
|
|
|
|
# # using persist_files to keep the temp directory around to avoid needing to grab another
|
|
|
|
|
# dest_result = self.runner._execute_module(conn, tmp, 'slurp', "path=%s" % dest, task_vars=task_vars, persist_files=True)
|
|
|
|
|
# if 'content' in dest_result.result:
|
|
|
|
|
# dest_contents = dest_result.result['content']
|
|
|
|
|
# if dest_result.result['encoding'] == 'base64':
|
|
|
|
|
# dest_contents = base64.b64decode(dest_contents)
|
|
|
|
|
# else:
|
|
|
|
|
# raise Exception("unknown encoding, failed: %s" % dest_result.result)
|
|
|
|
|
|
|
|
|
|
xfered = self._transfer_data(self._connection._shell.join_path(tmp, 'source'), resultant)
|
|
|
|
|
|
|
|
|
|
# fix file permissions when the copy is done as a different user
|
|
|
|
|
if self._play_context.become and self._play_context.become_user != 'root':
|
|
|
|
|
self._remote_chmod('a+r', xfered, tmp)
|
|
|
|
|
# if showing diffs, we need to get the remote value
|
|
|
|
|
if self._play_context.diff:
|
|
|
|
|
# using persist_files to keep the temp directory around to avoid needing to grab another
|
|
|
|
|
my_args = dict(path=dest)
|
|
|
|
|
dest_result = self._execute_module(module_name='slurp', module_args=my_args, task_vars=task_vars, persist_files=True)
|
|
|
|
|
if 'content' in dest_result:
|
|
|
|
|
dest_contents = dest_result['content']
|
|
|
|
|
if dest_result['encoding'] == 'base64':
|
|
|
|
|
dest_contents = base64.b64decode(dest_contents)
|
|
|
|
|
else:
|
|
|
|
|
raise Exception("unknown encoding, failed: %s" % dest_result)
|
|
|
|
|
|
|
|
|
|
if not self._play_context.check_mode: # do actual work thorugh copy
|
|
|
|
|
xfered = self._transfer_data(self._connection._shell.join_path(tmp, 'source'), resultant)
|
|
|
|
|
|
|
|
|
|
# fix file permissions when the copy is done as a different user
|
|
|
|
|
if self._play_context.become and self._play_context.become_user != 'root':
|
|
|
|
|
self._remote_chmod('a+r', xfered, tmp)
|
|
|
|
|
|
|
|
|
|
# run the copy module
|
|
|
|
|
new_module_args = self._task.args.copy()
|
|
|
|
|
new_module_args.update(
|
|
|
|
|
dict(
|
|
|
|
|
src=xfered,
|
|
|
|
|
dest=dest,
|
|
|
|
|
original_basename=os.path.basename(source),
|
|
|
|
|
follow=True,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
result = self._execute_module(module_name='copy', module_args=new_module_args, task_vars=task_vars)
|
|
|
|
|
else:
|
|
|
|
|
result=dict(changed=True)
|
|
|
|
|
|
|
|
|
|
# run the copy module
|
|
|
|
|
new_module_args = self._task.args.copy()
|
|
|
|
|
new_module_args.update(
|
|
|
|
|
dict(
|
|
|
|
|
src=xfered,
|
|
|
|
|
dest=dest,
|
|
|
|
|
original_basename=os.path.basename(source),
|
|
|
|
|
follow=True,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
if result.['changed'] and self._play_context.diff:
|
|
|
|
|
result['diff'] = dict(before=dest_contents, after=resultant, before_header=dest, after_header=source)
|
|
|
|
|
|
|
|
|
|
result = self._execute_module(module_name='copy', module_args=new_module_args, task_vars=task_vars)
|
|
|
|
|
if result.get('changed', False):
|
|
|
|
|
result['diff'] = dict(before=dest_contents, after=resultant)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
@ -177,5 +181,8 @@ class ActionModule(ActionBase):
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if self._play_context.check_mode:
|
|
|
|
|
new_module_args['CHECKMODE'] = True
|
|
|
|
|
|
|
|
|
|
return self._execute_module(module_name='file', module_args=new_module_args, task_vars=task_vars)
|
|
|
|
|
|
|
|
|
|
|