summaryrefslogtreecommitdiff
path: root/files
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2014-09-15 12:34:16 -0700
committerToshio Kuratomi <toshio@fedoraproject.org>2014-09-15 12:36:52 -0700
commit17665d962b49c6c74cc43c9a9ed5292b7b9dea70 (patch)
tree1a9bcc541cc02c54af756fc03725270a32e7dfc6 /files
parent4094edf92f3297f9dc9ed6c9fafb674927e1908c (diff)
downloadansible-modules-extras-17665d962b49c6c74cc43c9a9ed5292b7b9dea70.tar.gz
Do not keep a new file if we fail to set its attributes.
Diffstat (limited to 'files')
-rw-r--r--files/file12
1 files changed, 10 insertions, 2 deletions
diff --git a/files/file b/files/file
index 82f4d501..8bfd94dd 100644
--- a/files/file
+++ b/files/file
@@ -331,8 +331,16 @@ def main():
module.fail_json(path=path, msg='Error while touching existing target: %s' % str(e))
else:
module.fail_json(msg='Cannot touch other than files and directories')
-
- module.set_fs_attributes_if_different(file_args, True)
+ try:
+ module.set_fs_attributes_if_different(file_args, True)
+ except SystemExit as e:
+ if e.code:
+ # We take this to mean that fail_json() was called from
+ # somewhere in basic.py
+ if prev_state == 'absent':
+ # If we just created the file we can safely remove it
+ os.remove(path)
+ raise e
module.exit_json(dest=path, changed=True)