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
This commit is contained in:
Martin Krizek 2019-06-12 16:56:15 +02:00 committed by Brian Coca
parent d07d394779
commit 1fa7bfcd5d
3 changed files with 16 additions and 1 deletions

View file

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

View file

@ -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

View file

@ -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: