From 3afa8b373ebcb9856d42e7d5ad35cab0cfa78944 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sat, 11 May 2013 15:04:42 -0400 Subject: [PATCH] Improve check mode reporting for directories and file modes. --- lib/ansible/module_common.py | 8 ++++---- library/files/file | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index 31cf8df0be..8565f16d20 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -366,9 +366,9 @@ class AnsibleModule(object): uid = pwd.getpwnam(owner).pw_uid except KeyError: self.fail_json(path=path, msg='chown failed: failed to look up user %s' % owner) - if self.check_mode: - return True if orig_uid != uid: + if self.check_mode: + return True try: os.lchown(path, uid, -1) except OSError: @@ -388,9 +388,9 @@ class AnsibleModule(object): gid = grp.getgrnam(group).gr_gid except KeyError: self.fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group) - if self.check_mode: - return True if orig_gid != gid: + if self.check_mode: + return True try: os.lchown(path, -1, gid) except OSError: diff --git a/library/files/file b/library/files/file index 6cb51a33cf..ed957819eb 100644 --- a/library/files/file +++ b/library/files/file @@ -196,12 +196,14 @@ def main(): if prev_state != 'absent' and state == 'absent': try: if prev_state == 'directory': - if module.check_mode: - module.exit_json(changed=True) if os.path.islink(path): + if module.check_mode: + module.exit_json(changed=True) os.unlink(path) else: try: + if module.check_mode: + module.exit_json(changed=True) shutil.rmtree(path, ignore_errors=False) except: module.exit_json(msg="rmtree failed")