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:
parent
d07d394779
commit
1fa7bfcd5d
3 changed files with 16 additions and 1 deletions
2
changelogs/fragments/57618-fix-diff-on-absent-files.yaml
Normal file
2
changelogs/fragments/57618-fix-diff-on-absent-files.yaml
Normal file
|
@ -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…
Reference in a new issue