fix Windows env handling (#22927)

* fixes #22441
* fixes #22655
* moves all env handling into the exec wrapper; this should work for everything but raw, which is consistent with non-Windows.
This commit is contained in:
Matt Davis 2017-03-23 17:48:15 -07:00 committed by GitHub
commit 73f50b4f9f
8 changed files with 52 additions and 16 deletions

View file

@ -0,0 +1 @@
$env:taskenv

View file

@ -192,3 +192,16 @@
that:
- "test_script_bool_result.stdout_lines[0] == 'System.Boolean'"
- "test_script_bool_result.stdout_lines[1] == 'True'"
- name: run test script that uses envvars
script: test_script_with_env.ps1
environment:
taskenv: task
register: test_script_env_result
- name: ensure that script ran and that environment var was passed
assert:
that:
- test_script_env_result | succeeded
- test_script_env_result.stdout_lines[0] == 'task'

View file

@ -17,8 +17,10 @@
- shellout.stdout == "hello from Ansible\r\n"
- shellout.stdout_lines == ["hello from Ansible"]
- name: execute a powershell cmdlet with multi-line output
win_shell: Write-Output "hello from Ansible"; Write-Output "another line"; Write-Output "yet another line"
- name: execute a powershell cmdlet with multi-line output that uses environment with embedded quotes
win_shell: Write-Output "hello from Ansible"; Write-Output "another line"; Write-Output "yet another line"; Write-Output "envvar was $env:taskvar"
environment:
taskvar: "o'doyle rules"
register: shellout
- name: validate result
@ -26,15 +28,15 @@
that:
- shellout|success
- shellout|changed
- shellout.cmd == 'Write-Output "hello from Ansible"; Write-Output "another line"; Write-Output "yet another line"'
- shellout.cmd == 'Write-Output "hello from Ansible"; Write-Output "another line"; Write-Output "yet another line"; Write-Output "envvar was $env:taskvar"'
- shellout.delta is match('^\d:(\d){2}:(\d){2}.(\d){6}$')
- shellout.end is match('^(\d){4}\-(\d){2}\-(\d){2} (\d){2}:(\d){2}:(\d){2}.(\d){6}$')
- shellout.rc == 0
- shellout.start is match('^(\d){4}\-(\d){2}\-(\d){2} (\d){2}:(\d){2}:(\d){2}.(\d){6}$')
# assertion disabled since it does not pass on Windows Server 2016
# - shellout.stderr == ""
- shellout.stdout == "hello from Ansible\r\nanother line\r\nyet another line\r\n"
- shellout.stdout_lines == ["hello from Ansible","another line", "yet another line"]
- shellout.stdout == "hello from Ansible\r\nanother line\r\nyet another line\r\nenvvar was o'doyle rules\r\n"
- shellout.stdout_lines == ["hello from Ansible","another line", "yet another line", "envvar was o'doyle rules"]
- name: execute something nonexistent
win_shell: bogus_command1234