Merge pull request #514 from jbradberry/issue9546
Fix breakage in lineinfile check mode when target file does not exist.
This commit is contained in:
commit
c5f7fc93b2
1 changed files with 4 additions and 1 deletions
|
@ -192,7 +192,7 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create,
|
||||||
if not create:
|
if not create:
|
||||||
module.fail_json(rc=257, msg='Destination %s does not exist !' % dest)
|
module.fail_json(rc=257, msg='Destination %s does not exist !' % dest)
|
||||||
destpath = os.path.dirname(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)
|
os.makedirs(destpath)
|
||||||
lines = []
|
lines = []
|
||||||
else:
|
else:
|
||||||
|
@ -282,6 +282,9 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create,
|
||||||
backupdest = module.backup_local(dest)
|
backupdest = module.backup_local(dest)
|
||||||
write_changes(module, lines, 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)
|
msg, changed = check_file_attrs(module, changed, msg)
|
||||||
module.exit_json(changed=changed, msg=msg, backup=backupdest)
|
module.exit_json(changed=changed, msg=msg, backup=backupdest)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue