Improve check mode support in the file module.

reviewable/pr18780/r1
Michael DeHaan 12 years ago
parent bf021e25b8
commit 00fc43d676

10
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

Loading…
Cancel
Save