Skip to content

Commit

Permalink
win_powershell - fix empty array result value (#711)
Browse files Browse the repository at this point in the history
Fix to ensure `$Ansible.Result = @()` is returned as an empty array and
not null. This was a regression on a previous fix and this change goes
back to the original behaviour.
  • Loading branch information
jborean93 authored Dec 9, 2024
1 parent 04dc4a7 commit b6172c3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelogs/fragments/win_powershell-result-array.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- >-
win_powershell - Ensure ``$Ansible.Result = @()`` as an empty array is returned as an empty list and not null
- https://github.com/ansible-collections/ansible.windows/issues/686
2 changes: 1 addition & 1 deletion plugins/modules/win_powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ $OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = $utf8No
# https://github.com/ansible-collections/ansible.windows/issues/642
$resultPipeline = [PowerShell]::Create()
$resultPipeline.Runspace = $runspace
$result = $resultPipeline.AddScript('$Ansible').Invoke()
$result = $resultPipeline.AddScript('$Ansible').Invoke()[0]
}
finally {
if (-not $processId) {
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/targets/win_powershell/tasks/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@
- result_ansible.output == []
- result_ansible.result == ['1970-01-01T00:00:00.0000000Z', 'string']

- name: set empty array as Ansible.Result
win_powershell:
executable: '{{ pwsh_executable | default(omit) }}'
script: $Ansible.Result = @()
register: result_ansible

- name: assert set empty array as Ansible.Result
assert:
that:
- result_ansible is changed
- result_ansible.output == []
- result_ansible.result == []

- name: get temporary directory
win_powershell:
executable: '{{ pwsh_executable | default(omit) }}'
Expand Down

0 comments on commit b6172c3

Please sign in to comment.