[stable-2.6] Fix file module with check_mode - Fixes #42111 (#42115)

* Fix file module check_mode
(cherry picked from commit 22a6927)

Co-authored-by: Sloane Hertel <shertel@redhat.com>
pull/42223/head
Sloane Hertel 6 years ago committed by Matt Clay
parent e6aac0e1ff
commit 25ee10cd9a

@ -0,0 +1,5 @@
---
bugfixes:
- file module - The touch subcommand had its diff output broken during the
2.6.x development cycle. The patch to fix that broke check mode.
This is now fixed (https://github.com/ansible/ansible/issues/42111)

@ -322,6 +322,9 @@ def execute_touch(path, follow):
b_path = to_bytes(path, errors='surrogate_or_strict') b_path = to_bytes(path, errors='surrogate_or_strict')
prev_state = get_state(b_path) prev_state = get_state(b_path)
# Unfortunately, touch always changes the file because it updates file's timestamp
result = {'dest': path, 'changed': True}
if not module.check_mode: if not module.check_mode:
if prev_state == 'absent': if prev_state == 'absent':
# Create an empty file if the filename did not already exist # Create an empty file if the filename did not already exist
@ -369,8 +372,8 @@ def execute_touch(path, follow):
os.remove(b_path) os.remove(b_path)
raise raise
# Unfortunately, touch always changes the file because it updates file's timestamp result['diff'] = diff
return {'dest': path, 'changed': True, 'diff': diff} return result
def ensure_file_attributes(path, follow): def ensure_file_attributes(path, follow):

Loading…
Cancel
Save