New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix changes status and return diff information when state=touch and c… #59341
Conversation
@Andersson007, I added integration tests. Please take a look when you have a chance. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, several cosmetic suggestions.
I can't take a deep review now, maybe later
|
||
- name: verify touch updates only mtime when atime is preserved | ||
file: path={{output_dir}}/foo.txt state=touch access_time=preserve | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
- name: verify touch updated only atime when mtime is preserved | ||
file: path={{output_dir}}/foo.txt state=touch modification_time=preserve | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changelogs/fragments/touch_fix.yaml
Outdated
@@ -0,0 +1,2 @@ | |||
bugfixes: | |||
- file - Fix changed status and return diff information in file module when state=touch and check mode is set https://github.com/ansible/ansible/issues/50452 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- file - Fix changed status and return diff information in file module when state=touch and check mode is set https://github.com/ansible/ansible/issues/50452 | |
- file - Fix changed status and return diff information in file module when state=touch and check mode is set (https://github.com/ansible/ansible/issues/50452) |
@@ -0,0 +1,113 @@ | |||
# -*- coding: utf-8 -*- | |||
# Copyright: | |||
# (c) 2018 Ansible Project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# (c) 2018 Ansible Project |
@@ -0,0 +1,113 @@ | |||
# -*- coding: utf-8 -*- | |||
# Copyright: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Copyright: | |
# Copyright: 2018 Ansible Project |
The test
|
8bbe9b9
to
52b3bee
Compare
…heck_mode is set Fixes ansible#50452 * Add check_model parameter to update_timestamp_for_file function and the file timestamp only updates when check_mode is set to False (default option) * Changed is set to TRUE if file does not exist or the access_time and modification_time option are not set to preserve * Add unittest to test touch module in check mode Signed-off-by: Dmitry Nortsev <dmitry.nortsev@gmail.com>
52b3bee
to
c1241d9
Compare
@DSNortsev Could you please rebase the PR using https://docs.ansible.com/ansible/latest/dev_guide/developing_rebasing.html? Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. lib/ansible/modules/files/file.py
should now be lib/ansible/modules/file.py
.
# parameters are not set to "preserve" | ||
if prev_state == 'absent': | ||
result['changed'] = True | ||
elif module.params['access_time'] != 'preserve' or module.params['modification_time'] != 'preserve': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is handled by update_timestamp_for_file. You can simplify this and just do an if/else
elif module.params['access_time'] != 'preserve' or module.params['modification_time'] != 'preserve': | |
else: |
if prev_state == 'absent': | ||
result['changed'] = True | ||
elif module.params['access_time'] != 'preserve' or module.params['modification_time'] != 'preserve': | ||
result['changed'] = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this and add it to the conditional below
result['changed'] = True |
file_args = module.load_file_common_arguments(module.params) | ||
# Attach diff to result only when the file exists | ||
if update_timestamp_for_file(file_args['path'], mtime, atime, diff, check_mode=True): | ||
result['diff'] = diff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result['diff'] = diff | |
result['diff'] = diff | |
result['changed'] = True |
@DSNortsev any updates on this? |
Resolved by #79422 |
SUMMARY
Fixes #50452
only updates when check_mode is set to False (default option)
option are not set to preserve
ISSUE TYPE
COMPONENT NAME
file
ADDITIONAL INFORMATION
Playbook:
Playbook when access_time and modification_time are preserve:
Before Fix:
After Fix if file does not exist:
After Fix if file exists:
After fix if acccess_time and modification_time are set to preserve: