mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Use proper index value with insertbefore on a one line file (#46071)
Add tests and changelog
This commit is contained in:
parent
b6568c1c75
commit
b74279d14c
3 changed files with 34 additions and 1 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue