copy: print correct dest path when content + diff is used (#81678)

* when --diff is used with content parameter, print destination
  path instead of temporary file path.

Fixes: #79749

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/81586/head
Abhijeet Kasurde 1 year ago committed by GitHub
parent 243197f2d4
commit e4468dc944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
---
bugfixes:
- copy - print correct destination filename when using `content` and `--diff` (https://github.com/ansible/ansible/issues/79749).

@ -1339,7 +1339,7 @@ class ActionBase(ABC):
display.debug(u"_low_level_execute_command() done: rc=%d, stdout=%s, stderr=%s" % (rc, out, err)) display.debug(u"_low_level_execute_command() done: rc=%d, stdout=%s, stderr=%s" % (rc, out, err))
return dict(rc=rc, stdout=out, stdout_lines=out.splitlines(), stderr=err, stderr_lines=err.splitlines()) return dict(rc=rc, stdout=out, stdout_lines=out.splitlines(), stderr=err, stderr_lines=err.splitlines())
def _get_diff_data(self, destination, source, task_vars, source_file=True): def _get_diff_data(self, destination, source, task_vars, content, source_file=True):
# Note: Since we do not diff the source and destination before we transform from bytes into # Note: Since we do not diff the source and destination before we transform from bytes into
# text the diff between source and destination may not be accurate. To fix this, we'd need # text the diff between source and destination may not be accurate. To fix this, we'd need
@ -1396,6 +1396,9 @@ class ActionBase(ABC):
if b"\x00" in src_contents: if b"\x00" in src_contents:
diff['src_binary'] = 1 diff['src_binary'] = 1
else:
if content:
diff['after_header'] = destination
else: else:
diff['after_header'] = source diff['after_header'] = source
diff['after'] = to_text(src_contents) diff['after'] = to_text(src_contents)

@ -286,7 +286,7 @@ class ActionModule(ActionBase):
# The checksums don't match and we will change or error out. # The checksums don't match and we will change or error out.
if self._play_context.diff and not raw: if self._play_context.diff and not raw:
result['diff'].append(self._get_diff_data(dest_file, source_full, task_vars)) result['diff'].append(self._get_diff_data(dest_file, source_full, task_vars, content))
if self._play_context.check_mode: if self._play_context.check_mode:
self._remove_tempfile_if_content_defined(content, content_tempfile) self._remove_tempfile_if_content_defined(content, content_tempfile)

@ -84,6 +84,7 @@
- import_tasks: check_mode.yml - import_tasks: check_mode.yml
# https://github.com/ansible/ansible/issues/57618 # https://github.com/ansible/ansible/issues/57618
# https://github.com/ansible/ansible/issues/79749
- name: Test diff contents - name: Test diff contents
copy: copy:
content: 'Ansible managed\n' content: 'Ansible managed\n'
@ -95,6 +96,7 @@
that: that:
- 'diff_output.diff[0].before == ""' - 'diff_output.diff[0].before == ""'
- '"Ansible managed" in diff_output.diff[0].after' - '"Ansible managed" in diff_output.diff[0].after'
- '"file.txt" in diff_output.diff[0].after_header'
- name: tests with remote_src and non files - name: tests with remote_src and non files
import_tasks: src_remote_file_is_not_file.yml import_tasks: src_remote_file_is_not_file.yml

Loading…
Cancel
Save