mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Use proper index value with insertbefore on a one line file (#46071)
Add tests and changelog
This commit is contained in:
@@ -333,7 +333,7 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create,
|
||||
elif insertbefore and insertbefore != 'BOF':
|
||||
# If the line to insert before is at the beginning of the file
|
||||
# use the appropriate index value.
|
||||
if index[1] == 0:
|
||||
if index[1] <= 0:
|
||||
if b_lines[index[1]].rstrip(b('\r\n')) != b_line:
|
||||
b_lines.insert(index[1], b_line + b_linesep)
|
||||
msg = 'line replaced'
|
||||
|
||||
Reference in New Issue
Block a user