diff options
author | Anton Ovchinnikov <revolver112@gmail.com> | 2016-07-28 18:12:14 +0200 |
---|---|---|
committer | Adrian Likins <alikins@redhat.com> | 2016-07-28 12:12:14 -0400 |
commit | fc417a5ab06d43b6d65d0ccd73bb12b7f81e6a0a (patch) | |
tree | 51e2cb405051f27ebf6f5be3d9fbfcbe93b773c2 /files | |
parent | cd2dbed79c0815d1303d57006e0858e780897207 (diff) | |
download | ansible-modules-extras-fc417a5ab06d43b6d65d0ccd73bb12b7f81e6a0a.tar.gz |
Fix check mode for blockinfile when 'create: yes' is specified (#2413)
Make the module more semantically similar to lineinfile when
the destination does not exist. This fixes #2021.
Diffstat (limited to 'files')
-rwxr-xr-x | files/blockinfile.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/files/blockinfile.py b/files/blockinfile.py index 258284ea..38e719a9 100755 --- a/files/blockinfile.py +++ b/files/blockinfile.py @@ -212,7 +212,8 @@ def main(): module.fail_json(rc=256, msg='Destination %s is a directory !' % dest) - if not os.path.exists(dest): + path_exists = os.path.exists(dest) + if not path_exists: if not module.boolean(params['create']): module.fail_json(rc=257, msg='Destination %s does not exist !' % dest) @@ -230,6 +231,9 @@ def main(): marker = params['marker'] present = params['state'] == 'present' + if not present and not path_exists: + module.exit_json(changed=False, msg="File not present") + if insertbefore is None and insertafter is None: insertafter = 'EOF' @@ -299,10 +303,13 @@ def main(): changed = True if changed and not module.check_mode: - if module.boolean(params['backup']) and os.path.exists(dest): + if module.boolean(params['backup']) and path_exists: module.backup_local(dest) write_changes(module, result, dest) + if module.check_mode and not path_exists: + module.exit_json(changed=changed, msg=msg) + msg, changed = check_file_attrs(module, changed, msg) module.exit_json(changed=changed, msg=msg) |