mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-02 20:24:23 -07:00
Improve check mode support in the file module.
This commit is contained in:
parent
5af271911b
commit
4a4958f6c9
1 changed files with 14 additions and 4 deletions
10
library/file
10
library/file
|
@ -196,6 +196,8 @@ 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):
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
else:
|
else:
|
||||||
|
@ -204,6 +206,8 @@ def main():
|
||||||
except:
|
except:
|
||||||
module.exit_json(msg="rmtree failed")
|
module.exit_json(msg="rmtree failed")
|
||||||
else:
|
else:
|
||||||
|
if module.check_mode:
|
||||||
|
module.exit_json(changed=True)
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
module.fail_json(path=path, msg=str(e))
|
module.fail_json(path=path, msg=str(e))
|
||||||
|
@ -225,6 +229,8 @@ def main():
|
||||||
|
|
||||||
elif state == 'directory':
|
elif state == 'directory':
|
||||||
if prev_state == 'absent':
|
if prev_state == 'absent':
|
||||||
|
if module.check_mode:
|
||||||
|
module.exit_json(changed=True)
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
@ -254,6 +260,8 @@ def main():
|
||||||
module.fail_json(path=path, src=src, msg='src file does not exist')
|
module.fail_json(path=path, src=src, msg='src file does not exist')
|
||||||
|
|
||||||
if prev_state == 'absent':
|
if prev_state == 'absent':
|
||||||
|
if module.check_mode:
|
||||||
|
module.exit_json(changed=True)
|
||||||
os.symlink(src, path)
|
os.symlink(src, path)
|
||||||
changed = True
|
changed = True
|
||||||
elif prev_state == 'link':
|
elif prev_state == 'link':
|
||||||
|
@ -261,6 +269,8 @@ def main():
|
||||||
if not os.path.isabs(old_src):
|
if not os.path.isabs(old_src):
|
||||||
old_src = os.path.join(os.path.dirname(path), old_src)
|
old_src = os.path.join(os.path.dirname(path), old_src)
|
||||||
if old_src != src:
|
if old_src != src:
|
||||||
|
if module.check_mode:
|
||||||
|
module.exit_json(changed=True)
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
os.symlink(src, path)
|
os.symlink(src, path)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue