Do not insert extra newline if line already contains it
When using YAML multi-line strings, e.g.: - lineinfile: dest: /tmp/foo line: > foo bar the line already ends with a newline. If an extra newline is appended unconditionally it will lead to inserting an extra newline on each run.
This commit is contained in:
parent
9ad15cdae9
commit
fd69c5687b
1 changed files with 5 additions and 2 deletions
|
@ -245,8 +245,11 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create,
|
||||||
# Don't do backref expansion if not asked.
|
# Don't do backref expansion if not asked.
|
||||||
new_line = line
|
new_line = line
|
||||||
|
|
||||||
if lines[index[0]] != new_line + os.linesep:
|
if not new_line.endswith(os.linesep):
|
||||||
lines[index[0]] = new_line + os.linesep
|
new_line += os.linesep
|
||||||
|
|
||||||
|
if lines[index[0]] != new_line:
|
||||||
|
lines[index[0]] = new_line
|
||||||
msg = 'line replaced'
|
msg = 'line replaced'
|
||||||
changed = True
|
changed = True
|
||||||
elif backrefs:
|
elif backrefs:
|
||||||
|
|
Loading…
Reference in a new issue