Use proper index value with insertbefore on a one line file (#46071)

Add tests and changelog
This commit is contained in:
Sam Doran 2018-10-03 17:27:34 -04:00 committed by ansibot
commit b74279d14c
3 changed files with 34 additions and 1 deletions

View file

@ -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'