ini_file: fixes #1788, fails --check when file doesn't exist.

pull/18777/head
Luca Berruti 8 years ago committed by Matt Clay
parent fccaf883da
commit 1a22dde1ac

@ -126,17 +126,16 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
if not os.path.exists(filename): if not os.path.exists(filename):
try: ini_lines = []
open(filename,'w').close() else:
except: ini_file = open(filename, 'r')
module.fail_json(msg="Destination file %s not writable" % filename) try:
ini_file = open(filename, 'r') ini_lines = ini_file.readlines()
try: finally:
ini_lines = ini_file.readlines() ini_file.close()
# append a fake section line to simplify the logic
ini_lines.append('[') # append a fake section line to simplify the logic
finally: ini_lines.append('[')
ini_file.close()
within_section = not section within_section = not section
section_start = 0 section_start = 0
@ -242,8 +241,9 @@ def main():
(changed,backup_file) = do_ini(module, dest, section, option, value, state, backup, no_extra_spaces) (changed,backup_file) = do_ini(module, dest, section, option, value, state, backup, no_extra_spaces)
file_args = module.load_file_common_arguments(module.params) if not module.check_mode and os.path.exists(dest):
changed = module.set_fs_attributes_if_different(file_args, changed) file_args = module.load_file_common_arguments(module.params)
changed = module.set_fs_attributes_if_different(file_args, changed)
results = { 'changed': changed, 'msg': "OK", 'dest': dest } results = { 'changed': changed, 'msg': "OK", 'dest': dest }
if backup_file is not None: if backup_file is not None:

Loading…
Cancel
Save