From 22a6927dbd51c213cf8b81d8f5852332b54aa1b9 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Fri, 29 Jun 2018 14:19:34 -0400 Subject: [PATCH] Fix file module with check_mode - Fixes #42111 (#42115) * Fix file module check_mode --- changelogs/fragments/file_touch_check_mode.yaml | 5 +++++ lib/ansible/modules/files/file.py | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/file_touch_check_mode.yaml diff --git a/changelogs/fragments/file_touch_check_mode.yaml b/changelogs/fragments/file_touch_check_mode.yaml new file mode 100644 index 00000000000..41166d0a877 --- /dev/null +++ b/changelogs/fragments/file_touch_check_mode.yaml @@ -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) diff --git a/lib/ansible/modules/files/file.py b/lib/ansible/modules/files/file.py index 6fc56224825..bf1ed8a7842 100644 --- a/lib/ansible/modules/files/file.py +++ b/lib/ansible/modules/files/file.py @@ -322,6 +322,9 @@ def execute_touch(path, follow): b_path = to_bytes(path, errors='surrogate_or_strict') 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 prev_state == 'absent': # Create an empty file if the filename did not already exist @@ -369,8 +372,8 @@ def execute_touch(path, follow): os.remove(b_path) raise - # Unfortunately, touch always changes the file because it updates file's timestamp - return {'dest': path, 'changed': True, 'diff': diff} + result['diff'] = diff + return result def ensure_file_attributes(path, follow):