Improve check mode support in the file module.

This commit is contained in:
Michael DeHaan 2013-04-25 21:33:47 -04:00
parent 5af271911b
commit 4a4958f6c9

View file

@ -196,6 +196,8 @@ 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):
os.unlink(path)
else:
@ -204,6 +206,8 @@ def main():
except:
module.exit_json(msg="rmtree failed")
else:
if module.check_mode:
module.exit_json(changed=True)
os.unlink(path)
except Exception, e:
module.fail_json(path=path, msg=str(e))
@ -225,6 +229,8 @@ def main():
elif state == 'directory':
if prev_state == 'absent':
if module.check_mode:
module.exit_json(changed=True)
os.makedirs(path)
changed = True
@ -254,6 +260,8 @@ def main():
module.fail_json(path=path, src=src, msg='src file does not exist')
if prev_state == 'absent':
if module.check_mode:
module.exit_json(changed=True)
os.symlink(src, path)
changed = True
elif prev_state == 'link':
@ -261,6 +269,8 @@ def main():
if not os.path.isabs(old_src):
old_src = os.path.join(os.path.dirname(path), old_src)
if old_src != src:
if module.check_mode:
module.exit_json(changed=True)
os.unlink(path)
os.symlink(src, path)
changed = True
@ -270,10 +280,10 @@ def main():
# set modes owners and context as needed
file_args = module.load_file_common_arguments(module.params)
changed = module.set_context_if_different(path, file_args['secontext'], changed)
changed = module.set_owner_if_different(path, file_args['owner'], changed)
changed = module.set_group_if_different(path, file_args['group'], changed)
changed = module.set_mode_if_different(path, file_args['mode'], changed)
changed = module.set_context_if_different(path, file_args['secontext'], changed)
changed = module.set_owner_if_different(path, file_args['owner'], changed)
changed = module.set_group_if_different(path, file_args['group'], changed)
changed = module.set_mode_if_different(path, file_args['mode'], changed)
module.exit_json(dest=path, src=src, changed=changed)