1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Added check mode support to the ini_file module

This commit is contained in:
blxd 2015-02-23 11:14:38 +00:00 committed by Matt Clay
parent 1fcc1a7374
commit 35c414c271

View file

@ -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()