summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornichivo <nichivo@users.noreply.github.com>2016-09-19 16:56:29 +1000
committerRene Moser <mail@renemoser.net>2016-09-19 08:58:33 +0200
commitb0ea801bcbc3a6bedb74c88a2f5b4f66cc37f6fa (patch)
treed3f9d07bda6618a66e5aa632b73f669918e22c32
parent2b9300ec28330c77d9c7de4997ee82fe967df259 (diff)
downloadansible-modules-core-b0ea801bcbc3a6bedb74c88a2f5b4f66cc37f6fa.tar.gz
Insert missing option line before blank lines (#4747)
-rw-r--r--files/ini_file.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/files/ini_file.py b/files/ini_file.py
index ef4f8f56..fc45f761 100644
--- a/files/ini_file.py
+++ b/files/ini_file.py
@@ -156,8 +156,12 @@ def do_ini(module, filename, section=None, option=None, value=None, state='prese
if within_section:
if state == 'present':
# insert missing option line at the end of the section
- ini_lines.insert(index, assignment_format % (option, value))
- changed = True
+ 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]):
+ ini_lines.insert(i, assignment_format % (option, value))
+ changed = True
+ break
elif state == 'absent' and not option:
# remove the entire section
del ini_lines[section_start:index]