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

This commit is contained in:
Luca Berruti 2016-08-25 20:32:54 +02:00 committed by Matt Clay
parent fccaf883da
commit 1a22dde1ac

View file

@ -126,18 +126,17 @@ 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:
module.fail_json(msg="Destination file %s not writable" % filename)
ini_file = open(filename, 'r') ini_file = open(filename, 'r')
try: try:
ini_lines = ini_file.readlines() ini_lines = ini_file.readlines()
# append a fake section line to simplify the logic
ini_lines.append('[')
finally: finally:
ini_file.close() ini_file.close()
# append a fake section line to simplify the logic
ini_lines.append('[')
within_section = not section within_section = not section
section_start = 0 section_start = 0
changed = False changed = False
@ -242,6 +241,7 @@ 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)
if not module.check_mode and os.path.exists(dest):
file_args = module.load_file_common_arguments(module.params) file_args = module.load_file_common_arguments(module.params)
changed = module.set_fs_attributes_if_different(file_args, changed) changed = module.set_fs_attributes_if_different(file_args, changed)