Revert "ini_file: add support for lists of options/values"
Breaks "," values in INI files
This reverts commit af051d6f77
.
This commit is contained in:
parent
4a9f72dcce
commit
4dfbbc4499
1 changed files with 17 additions and 40 deletions
|
@ -108,21 +108,12 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
|
|||
changed = True
|
||||
else:
|
||||
if option is not None:
|
||||
if type(option) == str:
|
||||
try:
|
||||
if cp.get(section, option):
|
||||
cp.remove_option(section, option)
|
||||
changed = True
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
for o in option:
|
||||
try:
|
||||
if cp.get(section, o):
|
||||
cp.remove_option(section, o)
|
||||
changed = True
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if cp.get(section, option):
|
||||
cp.remove_option(section, option)
|
||||
changed = True
|
||||
except:
|
||||
pass
|
||||
|
||||
if state == 'present':
|
||||
if cp.has_section(section) == False:
|
||||
|
@ -133,31 +124,17 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
|
|||
changed = True
|
||||
|
||||
if option is not None and value is not None:
|
||||
olist = []
|
||||
vlist = []
|
||||
if type(option) == str and type(value) == str:
|
||||
olist.append(option)
|
||||
vlist.append(value)
|
||||
else:
|
||||
olist = list(option)
|
||||
vlist = list(value)
|
||||
if len(olist) != len(vlist):
|
||||
module.fail_json(msg="Option and value lists must be of same lengths")
|
||||
n = 0
|
||||
for option in olist:
|
||||
value = vlist[n]
|
||||
n = n + 1
|
||||
try:
|
||||
oldvalue = cp.get(section, option)
|
||||
if str(value) != str(oldvalue):
|
||||
cp.set(section, option, value)
|
||||
changed = True
|
||||
except ConfigParser.NoSectionError:
|
||||
cp.set(section, option, value)
|
||||
changed = True
|
||||
except ConfigParser.NoOptionError:
|
||||
try:
|
||||
oldvalue = cp.get(section, option)
|
||||
if str(value) != str(oldvalue):
|
||||
cp.set(section, option, value)
|
||||
changed = True
|
||||
except ConfigParser.NoSectionError:
|
||||
cp.set(section, option, value)
|
||||
changed = True
|
||||
except ConfigParser.NoOptionError:
|
||||
cp.set(section, option, value)
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
if backup:
|
||||
|
@ -180,8 +157,8 @@ def main():
|
|||
argument_spec = dict(
|
||||
dest = dict(required=True),
|
||||
section = dict(required=True),
|
||||
option = dict(required=False, type='list'),
|
||||
value = dict(required=False, type='list'),
|
||||
option = dict(required=False),
|
||||
value = dict(required=False),
|
||||
backup = dict(default='no', type='bool'),
|
||||
state = dict(default='present', choices=['present', 'absent'])
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue