summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2015-10-26 13:01:01 -0700
committerToshio Kuratomi <toshio@fedoraproject.org>2015-10-26 13:07:01 -0700
commit4b65a4a8b58bdeca8e15f4c9fa3c56edaaeb8f85 (patch)
tree03efecdde089b80e268c155fb4478736f77a3822
parentb058da9d1a304cb0a76115cf9930b9bfb8b82428 (diff)
downloadansible-modules-core-4b65a4a8b58bdeca8e15f4c9fa3c56edaaeb8f85.tar.gz
Simplify logic to handle options set to empty string
Fixes #2125 Conflicts: files/ini_file.py
-rw-r--r--files/ini_file.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/files/ini_file.py b/files/ini_file.py
index e247c265..590d0114 100644
--- a/files/ini_file.py
+++ b/files/ini_file.py
@@ -65,6 +65,12 @@ options:
description:
- all arguments accepted by the M(file) module also work here
required: false
+ state:
+ description:
+ - If set to C(absent) the option or section will be removed if present instead of created.
+ required: false
+ default: "present"
+ choices: [ "present", "absent" ]
notes:
- While it is possible to add an I(option) without specifying a I(value), this makes
no sense.
@@ -110,18 +116,14 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
if state == 'absent':
- if option is None and value is None:
- if cp.has_section(section):
- cp.remove_section(section)
- changed = True
+ if option is None:
+ changed = cp.remove_section(section)
else:
- if option is not None:
- try:
- if cp.get(section, option):
- cp.remove_option(section, option)
- changed = True
- except:
- pass
+ try:
+ changed = cp.remove_option(section, option)
+ except ConfigParser.NoSectionError:
+ # Option isn't present if the section isn't either
+ pass
if state == 'present':
@@ -206,4 +208,5 @@ def main():
# import module snippets
from ansible.module_utils.basic import *
-main()
+if __name__ == '__main__':
+ main()