Merge branch 'blxd-feature/ini_file_change_mode_support' into devel
This commit is contained in:
commit
b5c1b9b8f9
1 changed files with 7 additions and 6 deletions
|
@ -97,9 +97,9 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
if (sys.version_info[0] == 2 and sys.version_info[1] >= 7) or sys.version_info[0] >= 3:
|
if (sys.version_info[0] == 2 and sys.version_info[1] >= 7) or sys.version_info[0] >= 3:
|
||||||
cp = ConfigParser.ConfigParser(allow_no_value=True)
|
cp = ConfigParser.ConfigParser(allow_no_value=True)
|
||||||
else:
|
else:
|
||||||
cp = ConfigParser.ConfigParser()
|
cp = ConfigParser.ConfigParser()
|
||||||
cp.optionxform = identity
|
cp.optionxform = identity
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -126,7 +126,7 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
|
|
||||||
# DEFAULT section is always there by DEFAULT, so never try to add it.
|
# DEFAULT section is always there by DEFAULT, so never try to add it.
|
||||||
if cp.has_section(section) == False and section.upper() != 'DEFAULT':
|
if not cp.has_section(section) and section.upper() != 'DEFAULT':
|
||||||
|
|
||||||
cp.add_section(section)
|
cp.add_section(section)
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -144,7 +144,7 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
|
||||||
cp.set(section, option, value)
|
cp.set(section, option, value)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if changed:
|
if changed and not module.check_mode:
|
||||||
if backup:
|
if backup:
|
||||||
module.backup_local(filename)
|
module.backup_local(filename)
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
|
||||||
f = open(filename, 'w')
|
f = open(filename, 'w')
|
||||||
cp.write(f)
|
cp.write(f)
|
||||||
except:
|
except:
|
||||||
module.fail_json(msg="Can't creat %s" % filename)
|
module.fail_json(msg="Can't create %s" % filename)
|
||||||
|
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
|
@ -183,7 +183,8 @@ def main():
|
||||||
backup = dict(default='no', type='bool'),
|
backup = dict(default='no', type='bool'),
|
||||||
state = dict(default='present', choices=['present', 'absent'])
|
state = dict(default='present', choices=['present', 'absent'])
|
||||||
),
|
),
|
||||||
add_file_common_args = True
|
add_file_common_args = True,
|
||||||
|
supports_check_mode = True
|
||||||
)
|
)
|
||||||
|
|
||||||
info = dict()
|
info = dict()
|
||||||
|
|
Loading…
Reference in a new issue