Fix --diff to produce output when creating a new file (#57744)

* Fix --diff to produce output when creating a new file

Fixes #57618

* Make the check more defensive
pull/57762/head
Martin Krizek 6 years ago committed by Brian Coca
parent d07d394779
commit 1fa7bfcd5d

@ -0,0 +1,2 @@
bugfixes:
- "Fix --diff to produce output when creating a new file (https://github.com/ansible/ansible/issues/57618)"

@ -1104,7 +1104,7 @@ class ActionBase(with_metaclass(ABCMeta, object)):
if not peek_result.get('failed', False) or peek_result.get('rc', 0) == 0:
if peek_result.get('state') == 'absent':
if peek_result.get('state') in (None, 'absent'):
diff['before'] = u''
elif peek_result.get('appears_binary'):
diff['dst_binary'] = 1

@ -61,6 +61,19 @@
- import_tasks: acls.yml
when: ansible_system == 'Linux'
# https://github.com/ansible/ansible/issues/57618
- name: Test diff contents
copy:
content: 'Ansible managed\n'
dest: "{{ local_temp_dir }}/file.txt"
diff: yes
register: diff_output
- assert:
that:
- 'diff_output.diff[0].before == ""'
- '"Ansible managed" in diff_output.diff[0].after'
always:
- name: Cleaning
file:

Loading…
Cancel
Save