mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Improve check mode reporting for directories and file modes.
This commit is contained in:
parent
71f77d1583
commit
3afa8b373e
2 changed files with 8 additions and 6 deletions
|
@ -366,9 +366,9 @@ class AnsibleModule(object):
|
||||||
uid = pwd.getpwnam(owner).pw_uid
|
uid = pwd.getpwnam(owner).pw_uid
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.fail_json(path=path, msg='chown failed: failed to look up user %s' % owner)
|
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 orig_uid != uid:
|
||||||
|
if self.check_mode:
|
||||||
|
return True
|
||||||
try:
|
try:
|
||||||
os.lchown(path, uid, -1)
|
os.lchown(path, uid, -1)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -388,9 +388,9 @@ class AnsibleModule(object):
|
||||||
gid = grp.getgrnam(group).gr_gid
|
gid = grp.getgrnam(group).gr_gid
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group)
|
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 orig_gid != gid:
|
||||||
|
if self.check_mode:
|
||||||
|
return True
|
||||||
try:
|
try:
|
||||||
os.lchown(path, -1, gid)
|
os.lchown(path, -1, gid)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
|
|
@ -196,12 +196,14 @@ def main():
|
||||||
if prev_state != 'absent' and state == 'absent':
|
if prev_state != 'absent' and state == 'absent':
|
||||||
try:
|
try:
|
||||||
if prev_state == 'directory':
|
if prev_state == 'directory':
|
||||||
if module.check_mode:
|
|
||||||
module.exit_json(changed=True)
|
|
||||||
if os.path.islink(path):
|
if os.path.islink(path):
|
||||||
|
if module.check_mode:
|
||||||
|
module.exit_json(changed=True)
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
if module.check_mode:
|
||||||
|
module.exit_json(changed=True)
|
||||||
shutil.rmtree(path, ignore_errors=False)
|
shutil.rmtree(path, ignore_errors=False)
|
||||||
except:
|
except:
|
||||||
module.exit_json(msg="rmtree failed")
|
module.exit_json(msg="rmtree failed")
|
||||||
|
|
Loading…
Reference in a new issue