1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-06-15 20:37:43 +00:00
This commit is contained in:
Asif Draxi 2026-06-09 14:24:39 +05:30 committed by GitHub
commit 086a02e835
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 117 additions and 2 deletions

View file

@ -468,7 +468,10 @@ def do_ini(
# override option with no value to option with value if not allow_no_value
if len(values) > 0:
for index, line in enumerate(section_lines):
if not changed_lines[index] and match_function(option, line):
match = not changed_lines[index] and match_function(option, line)
# skip comment-only lines (e.g. "; output_buffering" with no "="):
# group(2) is the comment char, group(6) is "=" or "" (end-of-line match)
if match and not (match.group(2) and not match.group(6)):
newline = f"{option}{sep}{values.pop(0)}\n"
(changed, msg) = update_section_line(
option, changed, section_lines, index, changed_lines, ignore_spaces, newline, msg
@ -477,7 +480,9 @@ def do_ini(
break
# remove all remaining option occurrences from the rest of the section
for index in range(len(section_lines) - 1, 0, -1):
if not changed_lines[index] and match_function(option, section_lines[index]):
match = not changed_lines[index] and match_function(option, section_lines[index])
# skip comment-only lines (no "=") — only remove active or commented config lines
if match and not (match.group(2) and not match.group(6)):
del section_lines[index]
del changed_lines[index]
changed = True