diff options
author | Jeff Bradberry <jeff.bradberry@gmail.com> | 2014-12-14 20:48:36 -0500 |
---|---|---|
committer | Jeff Bradberry <jeff.bradberry@gmail.com> | 2014-12-14 20:48:36 -0500 |
commit | 28375aae7fcb4b89477e3eae6b1908a3fc169e72 (patch) | |
tree | 04d029a43d10c73e10ff3c35cba5c47ff8a6c723 /files | |
parent | b0c94cd6f634bccc3f2393a28a1e60478097483b (diff) | |
download | ansible-modules-core-28375aae7fcb4b89477e3eae6b1908a3fc169e72.tar.gz |
Fix breakage in lineinfile check mode when target file does not exist.
Similarly to https://github.com/ansible/ansible/issues/6182, checking of the file attributes should be avoided in check mode when the file didn't originally exist.
Also, avoid creating parent directories in check mode.
Fixes https://github.com/ansible/ansible/issues/9546
Diffstat (limited to 'files')
-rw-r--r-- | files/lineinfile.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/files/lineinfile.py b/files/lineinfile.py index ef73bde7..b9fc628e 100644 --- a/files/lineinfile.py +++ b/files/lineinfile.py @@ -192,7 +192,7 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, if not create: module.fail_json(rc=257, msg='Destination %s does not exist !' % dest) destpath = os.path.dirname(dest) - if not os.path.exists(destpath): + if not os.path.exists(destpath) and not module.check_mode: os.makedirs(destpath) lines = [] else: @@ -282,6 +282,9 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backupdest = module.backup_local(dest) write_changes(module, lines, dest) + if module.check_mode and not os.path.exists(dest): + module.exit_json(changed=changed, msg=msg, backup=backupdest) + msg, changed = check_file_attrs(module, changed, msg) module.exit_json(changed=changed, msg=msg, backup=backupdest) |