mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
[PR #3074/2831bc45 backport][stable-2] ini_file: fix empty-value vs. no-value inconsistency (#3181)
* ini_file: fix empty-value vs. no-value inconsistency (#3074)
* fix empty-value vs. no-value inconsistency
* rename changelog fragment
* tests: omit value where there should be no value
* add integration tests
(cherry picked from commit 2831bc45f5
)
* fixup backport
Co-authored-by: quidame <quidame@poivron.org>
This commit is contained in:
parent
e9356ad8fa
commit
009c88dc64
3 changed files with 25 additions and 10 deletions
|
@ -193,11 +193,11 @@ def do_ini(module, filename, section=None, option=None, value=None,
|
|||
for i in range(index, 0, -1):
|
||||
# search backwards for previous non-blank or non-comment line
|
||||
if not re.match(r'^[ \t]*([#;].*)?$', ini_lines[i - 1]):
|
||||
if option and value:
|
||||
if option and value is not None:
|
||||
ini_lines.insert(i, assignment_format % (option, value))
|
||||
msg = 'option added'
|
||||
changed = True
|
||||
elif option and not value and allow_no_value:
|
||||
elif option and value is None and allow_no_value:
|
||||
ini_lines.insert(i, '%s\n' % option)
|
||||
msg = 'option added'
|
||||
changed = True
|
||||
|
@ -213,7 +213,7 @@ def do_ini(module, filename, section=None, option=None, value=None,
|
|||
if state == 'present':
|
||||
# change the existing option line
|
||||
if match_opt(option, line):
|
||||
if not value and allow_no_value:
|
||||
if value is None and allow_no_value:
|
||||
newline = '%s\n' % option
|
||||
else:
|
||||
newline = assignment_format % (option, value)
|
||||
|
@ -311,7 +311,7 @@ def main():
|
|||
create = module.params['create']
|
||||
|
||||
if state == 'present' and not allow_no_value and value is None:
|
||||
module.fail_json("Parameter 'value' must not be empty if state=present and allow_no_value=False")
|
||||
module.fail_json("Parameter 'value' must be defined if state=present and allow_no_value=False")
|
||||
|
||||
(changed, backup_file, diff, msg) = do_ini(module, path, section, option, value, state, backup, no_extra_spaces, create, allow_no_value)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue