|
|
|
@ -72,6 +72,12 @@ options:
|
|
|
|
|
required: false
|
|
|
|
|
default: "present"
|
|
|
|
|
choices: [ "present", "absent" ]
|
|
|
|
|
no_extra_spaces:
|
|
|
|
|
description:
|
|
|
|
|
- do not insert spaces before and after '=' symbol
|
|
|
|
|
required: false
|
|
|
|
|
default: false
|
|
|
|
|
version_added: "2.1"
|
|
|
|
|
notes:
|
|
|
|
|
- While it is possible to add an I(option) without specifying a I(value), this makes
|
|
|
|
|
no sense.
|
|
|
|
@ -117,7 +123,7 @@ def match_active_opt(option, line):
|
|
|
|
|
# ==============================================================
|
|
|
|
|
# do_ini
|
|
|
|
|
|
|
|
|
|
def do_ini(module, filename, section=None, option=None, value=None, state='present', backup=False):
|
|
|
|
|
def do_ini(module, filename, section=None, option=None, value=None, state='present', backup=False, no_extra_spaces=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(filename):
|
|
|
|
@ -136,6 +142,10 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
|
|
|
|
|
within_section = not section
|
|
|
|
|
section_start = 0
|
|
|
|
|
changed = False
|
|
|
|
|
if no_extra_spaces:
|
|
|
|
|
assignment_format = '%s=%s\n'
|
|
|
|
|
else:
|
|
|
|
|
assignment_format = '%s = %s\n'
|
|
|
|
|
|
|
|
|
|
for index, line in enumerate(ini_lines):
|
|
|
|
|
if line.startswith('[%s]' % section):
|
|
|
|
@ -145,7 +155,7 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
|
|
|
|
|
if within_section:
|
|
|
|
|
if state == 'present':
|
|
|
|
|
# insert missing option line at the end of the section
|
|
|
|
|
ini_lines.insert(index, '%s = %s\n' % (option, value))
|
|
|
|
|
ini_lines.insert(index, assignment_format % (option, value))
|
|
|
|
|
changed = True
|
|
|
|
|
elif state == 'absent' and not option:
|
|
|
|
|
# remove the entire section
|
|
|
|
@ -157,7 +167,7 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
|
|
|
|
|
if state == 'present':
|
|
|
|
|
# change the existing option line
|
|
|
|
|
if match_opt(option, line):
|
|
|
|
|
newline = '%s = %s\n' % (option, value)
|
|
|
|
|
newline = assignment_format % (option, value)
|
|
|
|
|
changed = ini_lines[index] != newline
|
|
|
|
|
ini_lines[index] = newline
|
|
|
|
|
if changed:
|
|
|
|
@ -184,7 +194,7 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
|
|
|
|
|
|
|
|
|
|
if not within_section and option and state == 'present':
|
|
|
|
|
ini_lines.append('[%s]\n' % section)
|
|
|
|
|
ini_lines.append('%s = %s\n' % (option, value))
|
|
|
|
|
ini_lines.append(assignment_format % (option, value))
|
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -211,7 +221,8 @@ def main():
|
|
|
|
|
option = dict(required=False),
|
|
|
|
|
value = dict(required=False),
|
|
|
|
|
backup = dict(default='no', type='bool'),
|
|
|
|
|
state = dict(default='present', choices=['present', 'absent'])
|
|
|
|
|
state = dict(default='present', choices=['present', 'absent']),
|
|
|
|
|
no_extra_spaces = dict(required=False, default=False, type='bool')
|
|
|
|
|
),
|
|
|
|
|
add_file_common_args = True,
|
|
|
|
|
supports_check_mode = True
|
|
|
|
@ -225,8 +236,9 @@ def main():
|
|
|
|
|
value = module.params['value']
|
|
|
|
|
state = module.params['state']
|
|
|
|
|
backup = module.params['backup']
|
|
|
|
|
no_extra_spaces = module.params['no_extra_spaces']
|
|
|
|
|
|
|
|
|
|
changed = do_ini(module, dest, section, option, value, state, backup)
|
|
|
|
|
changed = do_ini(module, dest, section, option, value, state, backup, no_extra_spaces)
|
|
|
|
|
|
|
|
|
|
file_args = module.load_file_common_arguments(module.params)
|
|
|
|
|
changed = module.set_fs_attributes_if_different(file_args, changed)
|
|
|
|
|