mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-13 20:31:24 +00:00
Fixes for WinRM/PowerShell support in v2.
- Add support for inserting module args into PowerShell modules. Fixes #11661. - Support Windows paths containing spaces. Applies changes from #10727 to v2. Fixes #9999. Should also fix ansible/ansible-modules-core#944 and ansible/ansible-modules-core#1007. - Change how execution policy is set for running remote scripts. Applies changes from #11092 to v2. Also fixes ansible/ansible-modules-core#1776. - Use codepage 65001 (UTF-8) for WinRM connection instead of default (CP437), convert command to UTF-8 and results from UTF-8. Replaces changes from #10024. Fixes #11198. - Close WinRM connection when task completes. - Use win_stat, win_file and win_copy modules instead of stat, file and copy when called from within other action plugins (only when using WinRM+PowerShell). - Unquote Windows path arguments before passing to win_stat, win_file, win_copy and slurp modules (only when using WinRM/PowerShell). - Check for win_ping module to determine if core modules are missing (only when using WinRM/PowerShell). - Add stdout_lines to result from running low level commands (so stdout_lines is available when using raw/script). - Update copy action plugin to use shell functions for joining paths and checking for trailing slash. - Update fetch action plugin to unquote source path when using Windows paths. - Add win_copy and win_template action plugins that inherit from copy and template. - Support running .bat and .cmd scripts using default system encoding instead of UTF-8. - Always send PowerShell commands as base64-encoded blobs to allow for running simple PowerShell commands via raw. - Support running modules on Windows with interpreters other than PowerShell. - Update integration tests to support above changes and test unicode fixes. - Add test for win_user error from ansible/ansible-modules-core#1241 (fixed by ansible/ansible-modules-core#1774). - Add test for additional win_stat output values (implemented by ansible/ansible-modules-core#1473). - Add test for OS architecture and name from setup.ps1 (implemented by ansible/ansible-modules-core#1100). All WinRM integration tests pass for me with these changes.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
---
|
||||
win_output_dir: 'C:/temp/'
|
||||
win_output_dir: 'C:\ansible_testing'
|
||||
output_dir: ~/ansible_testing
|
||||
non_root_test_user: ansible
|
||||
pip_test_package: epdb
|
||||
|
||||
@@ -73,16 +73,14 @@
|
||||
- "fetch_flat_stat.stat.isreg"
|
||||
- "fetch_flat_stat.stat.md5 == fetch_flat.md5sum"
|
||||
|
||||
- name: fetch a small file to flat directory (without trailing slash)
|
||||
fetch: src="C:/Windows/win.ini" dest="{{ output_dir }}" flat=yes
|
||||
register: fetch_flat_dir
|
||||
ignore_errors: true
|
||||
#- name: fetch a small file to flat directory (without trailing slash)
|
||||
# fetch: src="C:/Windows/win.ini" dest="{{ output_dir }}" flat=yes
|
||||
# register: fetch_flat_dir
|
||||
|
||||
- name: check fetch flat to directory result
|
||||
assert:
|
||||
that:
|
||||
- "fetch_flat_dir|failed"
|
||||
- "fetch_flat_dir.msg"
|
||||
#- name: check fetch flat to directory result
|
||||
# assert:
|
||||
# that:
|
||||
# - "not fetch_flat_dir|changed"
|
||||
|
||||
- name: fetch a large binary file
|
||||
fetch: src="C:/Windows/explorer.exe" dest={{ output_dir }}
|
||||
@@ -114,7 +112,7 @@
|
||||
- "not fetch_large_again.changed"
|
||||
|
||||
- name: fetch a small file using backslashes in src path
|
||||
fetch: src="C:\Windows\system.ini" dest={{ output_dir }}
|
||||
fetch: src="C:\\Windows\\system.ini" dest={{ output_dir }}
|
||||
register: fetch_small_bs
|
||||
|
||||
- name: check fetch small result with backslashes
|
||||
@@ -157,7 +155,7 @@
|
||||
- "not fetch_missing|changed"
|
||||
|
||||
- name: attempt to fetch a directory
|
||||
fetch: src="C:\Windows" dest={{ output_dir }}
|
||||
fetch: src="C:\\Windows" dest={{ output_dir }}
|
||||
register: fetch_dir
|
||||
ignore_errors: true
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
# - "file_result.state == 'file'"
|
||||
|
||||
- name: verify that we are checking an absent file
|
||||
win_file: path={{win_output_dir}}\bar.txt state=absent
|
||||
win_file: path={{win_output_dir}}/bar.txt state=absent
|
||||
register: file2_result
|
||||
|
||||
- name: verify that the file was marked as changed
|
||||
@@ -42,7 +42,7 @@
|
||||
# - "file2_result.state == 'absent'"
|
||||
|
||||
- name: verify we can touch a file
|
||||
win_file: path={{win_output_dir}}\baz.txt state=touch
|
||||
win_file: path={{win_output_dir}}/baz.txt state=touch
|
||||
register: file3_result
|
||||
|
||||
- name: verify that the file was marked as changed
|
||||
@@ -85,8 +85,8 @@
|
||||
# - "chown_result.failed == True"
|
||||
# - "file_exists_result.stat.exists == False"
|
||||
#
|
||||
- name: clean up
|
||||
win_file: path=/tmp/worldwritable state=absent
|
||||
#- name: clean up
|
||||
# win_file: path=/tmp/worldwritable state=absent
|
||||
|
||||
#- name: create soft link to file
|
||||
# win_file: src={{output_file}} dest={{win_output_dir}}/soft.txt state=link
|
||||
@@ -107,7 +107,7 @@
|
||||
# - "file6_result.changed == true"
|
||||
#
|
||||
- name: create a directory
|
||||
win_file: path={{win_output_dir}}\foobar state=directory
|
||||
win_file: path={{win_output_dir}}/foobar state=directory
|
||||
register: file7_result
|
||||
|
||||
- debug: var=file7_result
|
||||
@@ -134,22 +134,22 @@
|
||||
# when: selinux_installed.stdout != "" and selinux_enabled.stdout != "Disabled"
|
||||
|
||||
- name: remote directory foobar
|
||||
win_file: path={{win_output_dir}}\foobar state=absent
|
||||
win_file: path={{win_output_dir}}/foobar state=absent
|
||||
|
||||
- name: remove file foo.txt
|
||||
win_file: path={{win_output_dir}}\foo.txt state=absent
|
||||
win_file: path={{win_output_dir}}/foo.txt state=absent
|
||||
|
||||
- name: remove file bar.txt
|
||||
win_file: path={{win_output_dir}}\foo.txt state=absent
|
||||
win_file: path={{win_output_dir}}/foo.txt state=absent
|
||||
|
||||
- name: remove file baz.txt
|
||||
win_file: path={{win_output_dir}}\foo.txt state=absent
|
||||
win_file: path={{win_output_dir}}/foo.txt state=absent
|
||||
|
||||
- name: win copy directory structure over
|
||||
win_copy: src=foobar dest={{win_output_dir}}
|
||||
|
||||
- name: remove directory foobar
|
||||
win_file: path={{win_output_dir}}\foobar state=absent
|
||||
win_file: path={{win_output_dir}}/foobar state=absent
|
||||
register: file14_result
|
||||
|
||||
- debug: var=file14_result
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- name: use win_get_url module to download msi
|
||||
win_get_url: url=http://downloads.sourceforge.net/project/sevenzip/7-Zip/9.22/7z922-x64.msi dest='C:\7z922-x64.msi'
|
||||
win_get_url: url=http://downloads.sourceforge.net/project/sevenzip/7-Zip/9.22/7z922-x64.msi dest='C:\\7z922-x64.msi'
|
||||
register: win_get_url_result
|
||||
|
||||
- name: install 7zip msi
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
- "win_ping_result.ping == 'pong'"
|
||||
|
||||
- name: test win_ping with data
|
||||
win_ping: data=blah
|
||||
win_ping: data=☠
|
||||
register: win_ping_with_data_result
|
||||
|
||||
- name: check win_ping result with data
|
||||
@@ -36,21 +36,11 @@
|
||||
that:
|
||||
- "not win_ping_with_data_result|failed"
|
||||
- "not win_ping_with_data_result|changed"
|
||||
- "win_ping_with_data_result.ping == 'blah'"
|
||||
- "win_ping_with_data_result.ping == '☠'"
|
||||
|
||||
#- name: test local ping (should use default ping)
|
||||
# local_action: ping
|
||||
# register: local_ping_result
|
||||
|
||||
#- name: check local ping result
|
||||
# assert:
|
||||
# that:
|
||||
# - "not local_ping_result|failed"
|
||||
# - "not local_ping_result|changed"
|
||||
# - "local_ping_result.ping == 'pong'"
|
||||
|
||||
- name: test win_ping.ps1 with data
|
||||
win_ping.ps1: data=bleep
|
||||
- name: test win_ping.ps1 with data as complex args
|
||||
win_ping.ps1:
|
||||
data: bleep
|
||||
register: win_ping_ps1_result
|
||||
|
||||
- name: check win_ping.ps1 result with data
|
||||
@@ -60,13 +50,32 @@
|
||||
- "not win_ping_ps1_result|changed"
|
||||
- "win_ping_ps1_result.ping == 'bleep'"
|
||||
|
||||
#- name: test win_ping with invalid args
|
||||
# win_ping: arg=invalid
|
||||
# register: win_ping_ps1_invalid_args_result
|
||||
|
||||
#- name: check that win_ping.ps1 with invalid args fails
|
||||
# assert:
|
||||
# that:
|
||||
# - "win_ping_ps1_invalid_args_result|failed"
|
||||
# - "win_ping_ps1_invalid_args_result.msg"
|
||||
- name: test win_ping with extra args to verify that v2 module replacer escaping works as expected
|
||||
win_ping:
|
||||
data: bloop
|
||||
a_null: null
|
||||
a_boolean: true
|
||||
another_boolean: false
|
||||
a_number: 299792458
|
||||
another_number: 22.7
|
||||
yet_another_number: 6.022e23
|
||||
a_string: |
|
||||
it's magic
|
||||
"@'
|
||||
'@"
|
||||
an_array:
|
||||
- first
|
||||
- 2
|
||||
- 3.0
|
||||
an_object:
|
||||
- the_thing: the_value
|
||||
- the_other_thing: 0
|
||||
- the_list_of_things: [1, 2, 3, 5]
|
||||
register: win_ping_extra_args_result
|
||||
|
||||
- name: check that win_ping with extra args succeeds and ignores everything except data
|
||||
assert:
|
||||
that:
|
||||
- "not win_ping_extra_args_result|failed"
|
||||
- "not win_ping_extra_args_result|changed"
|
||||
- "win_ping_extra_args_result.ping == 'bloop'"
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
- "not unknown_result|changed"
|
||||
|
||||
- name: run a command that takes longer than 60 seconds
|
||||
raw: PowerShell -Command Start-Sleep -s 75
|
||||
raw: Start-Sleep -s 75
|
||||
register: sleep_command
|
||||
|
||||
- name: assert that the sleep command ran
|
||||
|
||||
@@ -3,3 +3,4 @@
|
||||
# Parameters to pass to test scripts.
|
||||
test_win_script_value: VaLuE
|
||||
test_win_script_splat: "@{This='THIS'; That='THAT'; Other='OTHER'}"
|
||||
test_win_script_filename: "C:/Users/{{ansible_ssh_user}}/testing_win_script.txt"
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
@ECHO OFF
|
||||
ECHO We can even run a batch file with cmd extension!
|
||||
@@ -0,0 +1,3 @@
|
||||
# Test script to create a file.
|
||||
|
||||
echo $null > $args[0]
|
||||
@@ -0,0 +1,3 @@
|
||||
# Test script to remove a file.
|
||||
|
||||
Remove-Item $args[0] -Force
|
||||
@@ -30,24 +30,24 @@
|
||||
- "not test_script_result|failed"
|
||||
- "test_script_result|changed"
|
||||
|
||||
- name: run test script that takes arguments
|
||||
script: test_script_with_args.ps1 /this /that /other
|
||||
- name: run test script that takes arguments including a unicode char
|
||||
script: test_script_with_args.ps1 /this /that /Ӧther
|
||||
register: test_script_with_args_result
|
||||
|
||||
- name: check that script ran and received arguments
|
||||
- name: check that script ran and received arguments and returned unicode
|
||||
assert:
|
||||
that:
|
||||
- "test_script_with_args_result.rc == 0"
|
||||
- "test_script_with_args_result.stdout"
|
||||
- "test_script_with_args_result.stdout_lines[0] == '/this'"
|
||||
- "test_script_with_args_result.stdout_lines[1] == '/that'"
|
||||
- "test_script_with_args_result.stdout_lines[2] == '/other'"
|
||||
- "test_script_with_args_result.stdout_lines[2] == '/Ӧther'"
|
||||
- "not test_script_with_args_result.stderr"
|
||||
- "not test_script_with_args_result|failed"
|
||||
- "test_script_with_args_result|changed"
|
||||
|
||||
- name: run test script that takes parameters passed via splatting
|
||||
script: test_script_with_splatting.ps1 "@{ This = 'this'; That = '{{ test_win_script_value }}'; Other = 'other'}"
|
||||
script: test_script_with_splatting.ps1 @{ This = 'this'; That = '{{ test_win_script_value }}'; Other = 'other'}
|
||||
register: test_script_with_splatting_result
|
||||
|
||||
- name: check that script ran and received parameters via splatting
|
||||
@@ -63,7 +63,7 @@
|
||||
- "test_script_with_splatting_result|changed"
|
||||
|
||||
- name: run test script that takes splatted parameters from a variable
|
||||
script: test_script_with_splatting.ps1 {{ test_win_script_splat|quote }}
|
||||
script: test_script_with_splatting.ps1 {{ test_win_script_splat }}
|
||||
register: test_script_with_splatting2_result
|
||||
|
||||
- name: check that script ran and received parameters via splatting from a variable
|
||||
@@ -92,6 +92,58 @@
|
||||
- "test_script_with_errors_result|failed"
|
||||
- "test_script_with_errors_result|changed"
|
||||
|
||||
- name: cleanup test file if it exists
|
||||
raw: Remove-Item "{{test_win_script_filename}}" -Force
|
||||
ignore_errors: true
|
||||
|
||||
- name: run test script that creates a file
|
||||
script: test_script_creates_file.ps1 "{{test_win_script_filename}}" creates="{{test_win_script_filename}}"
|
||||
register: test_script_creates_file_result
|
||||
|
||||
- name: check that script ran and indicated a change
|
||||
assert:
|
||||
that:
|
||||
- "test_script_creates_file_result.rc == 0"
|
||||
- "not test_script_creates_file_result.stdout"
|
||||
- "not test_script_creates_file_result.stderr"
|
||||
- "not test_script_creates_file_result|failed"
|
||||
- "test_script_creates_file_result|changed"
|
||||
|
||||
- name: run test script that creates a file again
|
||||
script: test_script_creates_file.ps1 "{{test_win_script_filename}}" creates="{{test_win_script_filename}}"
|
||||
register: test_script_creates_file_again_result
|
||||
|
||||
- name: check that the script did not run since the remote file exists
|
||||
assert:
|
||||
that:
|
||||
- "not test_script_creates_file_again_result|failed"
|
||||
- "not test_script_creates_file_again_result|changed"
|
||||
- "test_script_creates_file_again_result|skipped"
|
||||
|
||||
- name: run test script that removes a file
|
||||
script: test_script_removes_file.ps1 "{{test_win_script_filename}}" removes="{{test_win_script_filename}}"
|
||||
register: test_script_removes_file_result
|
||||
|
||||
- name: check that the script ran since the remote file exists
|
||||
assert:
|
||||
that:
|
||||
- "test_script_removes_file_result.rc == 0"
|
||||
- "not test_script_removes_file_result.stdout"
|
||||
- "not test_script_removes_file_result.stderr"
|
||||
- "not test_script_removes_file_result|failed"
|
||||
- "test_script_removes_file_result|changed"
|
||||
|
||||
- name: run test script that removes a file again
|
||||
script: test_script_removes_file.ps1 "{{test_win_script_filename}}" removes="{{test_win_script_filename}}"
|
||||
register: test_script_removes_file_again_result
|
||||
|
||||
- name: check that the script did not run since the remote file does not exist
|
||||
assert:
|
||||
that:
|
||||
- "not test_script_removes_file_again_result|failed"
|
||||
- "not test_script_removes_file_again_result|changed"
|
||||
- "test_script_removes_file_again_result|skipped"
|
||||
|
||||
- name: run simple batch file
|
||||
script: test_script.bat
|
||||
register: test_batch_result
|
||||
@@ -105,3 +157,17 @@
|
||||
- "not test_batch_result.stderr"
|
||||
- "not test_batch_result|failed"
|
||||
- "test_batch_result|changed"
|
||||
|
||||
- name: run simple batch file with .cmd extension
|
||||
script: test_script.cmd
|
||||
register: test_cmd_result
|
||||
|
||||
- name: check that batch file with .cmd extension ran
|
||||
assert:
|
||||
that:
|
||||
- "test_cmd_result.rc == 0"
|
||||
- "test_cmd_result.stdout"
|
||||
- "'cmd extension' in test_cmd_result.stdout"
|
||||
- "not test_cmd_result.stderr"
|
||||
- "not test_cmd_result|failed"
|
||||
- "test_cmd_result|changed"
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
action: setup
|
||||
register: setup_result
|
||||
|
||||
- name: check setup result
|
||||
- name: check windows setup result
|
||||
assert:
|
||||
that:
|
||||
- "not setup_result|failed"
|
||||
@@ -38,6 +38,8 @@
|
||||
- "setup_result.ansible_facts.ansible_interfaces[0]"
|
||||
- "setup_result.ansible_facts.ansible_interfaces[0].interface_name"
|
||||
- "setup_result.ansible_facts.ansible_interfaces[0].interface_index"
|
||||
- "setup_result.ansible_facts.ansible_architecture"
|
||||
- "setup_result.ansible_facts.ansible_os_name"
|
||||
- "setup_result.ansible_facts.ansible_powershell_version"
|
||||
|
||||
- name: check setup result only when using https
|
||||
|
||||
@@ -27,6 +27,12 @@
|
||||
- "not win_stat_file.stat.isdir"
|
||||
- "win_stat_file.stat.size > 0"
|
||||
- "win_stat_file.stat.md5"
|
||||
- "win_stat_file.stat.extension"
|
||||
- "win_stat_file.stat.attributes"
|
||||
- "win_stat_file.stat.owner"
|
||||
- "win_stat_file.stat.creationtime"
|
||||
- "win_stat_file.stat.lastaccesstime"
|
||||
- "win_stat_file.stat.lastwritetime"
|
||||
- "not win_stat_file|failed"
|
||||
- "not win_stat_file|changed"
|
||||
|
||||
@@ -34,13 +40,19 @@
|
||||
win_stat: path="C:\Windows\win.ini" get_md5=no
|
||||
register: win_stat_file_no_md5
|
||||
|
||||
- name: check win_stat file result without md
|
||||
- name: check win_stat file result without md5
|
||||
assert:
|
||||
that:
|
||||
- "win_stat_file_no_md5.stat.exists"
|
||||
- "not win_stat_file_no_md5.stat.isdir"
|
||||
- "win_stat_file_no_md5.stat.size > 0"
|
||||
- "not win_stat_file_no_md5.stat.md5|default('')"
|
||||
- "win_stat_file_no_md5.stat.extension"
|
||||
- "win_stat_file_no_md5.stat.attributes"
|
||||
- "win_stat_file_no_md5.stat.owner"
|
||||
- "win_stat_file_no_md5.stat.creationtime"
|
||||
- "win_stat_file_no_md5.stat.lastaccesstime"
|
||||
- "win_stat_file_no_md5.stat.lastwritetime"
|
||||
- "not win_stat_file_no_md5|failed"
|
||||
- "not win_stat_file_no_md5|changed"
|
||||
|
||||
@@ -53,6 +65,12 @@
|
||||
that:
|
||||
- "win_stat_dir.stat.exists"
|
||||
- "win_stat_dir.stat.isdir"
|
||||
- "win_stat_dir.stat.extension == ''"
|
||||
- "win_stat_dir.stat.attributes"
|
||||
- "win_stat_dir.stat.owner"
|
||||
- "win_stat_dir.stat.creationtime"
|
||||
- "win_stat_dir.stat.lastaccesstime"
|
||||
- "win_stat_dir.stat.lastwritetime"
|
||||
- "not win_stat_dir|failed"
|
||||
- "not win_stat_dir|changed"
|
||||
|
||||
|
||||
@@ -42,10 +42,10 @@
|
||||
# VERIFY CONTENTS
|
||||
|
||||
- name: copy known good into place
|
||||
win_copy: src=foo.txt dest={{win_output_dir}}\foo.txt
|
||||
win_copy: src=foo.txt dest={{win_output_dir}}\\foo.txt
|
||||
|
||||
- name: compare templated file to known good
|
||||
raw: fc.exe {{win_output_dir}}\foo.templated {{win_output_dir}}\foo.txt
|
||||
raw: fc.exe {{win_output_dir}}\\foo.templated {{win_output_dir}}\\foo.txt
|
||||
register: diff_result
|
||||
|
||||
- debug: var=diff_result
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
- "win_user_missing_query_result.state == 'absent'"
|
||||
|
||||
- name: test create user
|
||||
win_user: name="{{ test_win_user_name }}" password="{{ test_win_user_password }}" groups="Guests"
|
||||
win_user: name="{{ test_win_user_name }}" password="{{ test_win_user_password }}" fullname="Test User" description="Test user account" groups="Guests"
|
||||
register: win_user_create_result
|
||||
|
||||
- name: check user creation result
|
||||
@@ -59,7 +59,8 @@
|
||||
that:
|
||||
- "win_user_create_result|changed"
|
||||
- "win_user_create_result.name == '{{ test_win_user_name }}'"
|
||||
- "win_user_create_result.fullname == '{{ test_win_user_name }}'"
|
||||
- "win_user_create_result.fullname == 'Test User'"
|
||||
- "win_user_create_result.description == 'Test user account'"
|
||||
- "win_user_create_result.path"
|
||||
- "win_user_create_result.state == 'present'"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user