From efda3eaf1cb84799287ae3569d2022b9f8a72f1d Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Wed, 19 Dec 2018 05:39:25 +1000 Subject: [PATCH] win_lineinfile - fix malformed returned json (#50066) --- changelogs/fragments/win_lineinfile-output.yaml | 2 ++ lib/ansible/modules/windows/win_lineinfile.ps1 | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/win_lineinfile-output.yaml diff --git a/changelogs/fragments/win_lineinfile-output.yaml b/changelogs/fragments/win_lineinfile-output.yaml new file mode 100644 index 00000000000..7a0c523db2f --- /dev/null +++ b/changelogs/fragments/win_lineinfile-output.yaml @@ -0,0 +1,2 @@ +bugfixes: +- win_lineinfile - Fix issue where a malformed json block was returned causing an error diff --git a/lib/ansible/modules/windows/win_lineinfile.ps1 b/lib/ansible/modules/windows/win_lineinfile.ps1 index 0960b24736a..2c2eb9a8037 100644 --- a/lib/ansible/modules/windows/win_lineinfile.ps1 +++ b/lib/ansible/modules/windows/win_lineinfile.ps1 @@ -183,7 +183,7 @@ function Present($path, $regexp, $line, $insertafter, $insertbefore, $create, $b $result.msg = "line added"; } ElseIf ($insertafter -eq "EOF" -or $index[1] -eq -1) { - $lines.Add($line); + $lines.Add($line) > $null; $result.changed = $true; $result.msg = "line added"; } @@ -265,11 +265,11 @@ function Absent($path, $regexp, $line, $backup, $validate, $encodingobj, $linese $match_found = $line -ceq $cur_line; } If ($match_found) { - $found.Add($cur_line); + $found.Add($cur_line) > $null; $result.changed = $true; } Else { - $left.Add($cur_line); + $left.Add($cur_line) > $null; } } @@ -351,7 +351,7 @@ ElseIf (Test-Path -LiteralPath $path) { $max_preamble_len = $plen; } If ($plen -gt 0) { - $sortedlist.Add(-($plen * 1000000 + $encoding.CodePage), $encoding); + $sortedlist.Add(-($plen * 1000000 + $encoding.CodePage), $encoding) > $null; } }