mirror of https://github.com/ansible/ansible.git
Add winrm integration tests for raw, script and ping modules.
parent
fa0943a9b3
commit
0c938562a7
@ -0,0 +1,7 @@
|
||||
[windows]
|
||||
server ansible_ssh_host=10.10.10.10 ansible_ssh_user=Administrator ansible_ssh_pass=ShhhDontTellAnyone
|
||||
|
||||
[windows:vars]
|
||||
ansible_connection=winrm
|
||||
# HTTPS uses 5986, HTTP uses 5985
|
||||
ansible_ssh_port=5985
|
||||
@ -0,0 +1,66 @@
|
||||
---
|
||||
|
||||
- name: test win_ping
|
||||
action: win_ping
|
||||
register: win_ping_result
|
||||
|
||||
- name: check win_ping result
|
||||
assert:
|
||||
that:
|
||||
- "not win_ping_result|failed"
|
||||
- "not win_ping_result|changed"
|
||||
- "win_ping_result.ping == 'pong'"
|
||||
|
||||
- name: test win_ping with data
|
||||
win_ping: data=blah
|
||||
register: win_ping_with_data_result
|
||||
|
||||
- name: check win_ping result with data
|
||||
assert:
|
||||
that:
|
||||
- "not win_ping_with_data_result|failed"
|
||||
- "not win_ping_with_data_result|changed"
|
||||
- "win_ping_with_data_result.ping == 'blah'"
|
||||
|
||||
- name: test ping.ps1 with data
|
||||
ping.ps1: data=bleep
|
||||
register: ping_ps1_result
|
||||
|
||||
- name: check ping.ps1 result
|
||||
assert:
|
||||
that:
|
||||
- "not ping_ps1_result|failed"
|
||||
- "not ping_ps1_result|changed"
|
||||
- "ping_ps1_result.ping == 'bleep'"
|
||||
|
||||
#- name: test ping.ps1 with invalid args
|
||||
# ping.ps1: arg=invalid
|
||||
# register: ping_ps1_invalid_args_result
|
||||
|
||||
#- name: check that ping.ps1 with invalid args fails
|
||||
# assert:
|
||||
# that:
|
||||
# - "ping_ps1_invalid_args_result|failed"
|
||||
# - "ping_ps1_invalid_args_result.msg"
|
||||
|
||||
- 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 ping (should use ping.ps1)
|
||||
action: ping
|
||||
register: ping_result
|
||||
|
||||
- name: check ping result
|
||||
assert:
|
||||
that:
|
||||
- "not ping_result|failed"
|
||||
- "not ping_result|changed"
|
||||
- "ping_result.ping == 'pong'"
|
||||
@ -0,0 +1,56 @@
|
||||
---
|
||||
|
||||
- name: run getmac
|
||||
raw: getmac
|
||||
register: getmac_result
|
||||
|
||||
- name: assert that getmac ran
|
||||
assert:
|
||||
that:
|
||||
- "getmac_result.rc == 0"
|
||||
- "getmac_result.stdout"
|
||||
- "not getmac_result.stderr"
|
||||
- "not getmac_result|failed"
|
||||
- "not getmac_result|changed"
|
||||
|
||||
- name: run ipconfig with /all argument
|
||||
raw: ipconfig /all
|
||||
register: ipconfig_result
|
||||
|
||||
- name: assert that ipconfig ran with /all argument
|
||||
assert:
|
||||
that:
|
||||
- "ipconfig_result.rc == 0"
|
||||
- "ipconfig_result.stdout"
|
||||
- "'Physical Address' in ipconfig_result.stdout"
|
||||
- "not ipconfig_result.stderr"
|
||||
- "not ipconfig_result|failed"
|
||||
- "not ipconfig_result|changed"
|
||||
|
||||
- name: run ipconfig with invalid argument
|
||||
raw: ipconfig /badswitch
|
||||
register: ipconfig_invalid_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: assert that ipconfig with invalid argument failed
|
||||
assert:
|
||||
that:
|
||||
- "ipconfig_invalid_result.rc != 0"
|
||||
- "ipconfig_invalid_result.stdout" # ipconfig displays errors on stdout.
|
||||
- "not ipconfig_invalid_result.stderr"
|
||||
- "ipconfig_invalid_result|failed"
|
||||
- "not ipconfig_invalid_result|changed"
|
||||
|
||||
- name: run an unknown command
|
||||
raw: uname -a
|
||||
register: unknown_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: assert that an unknown command failed
|
||||
assert:
|
||||
that:
|
||||
- "unknown_result.rc != 0"
|
||||
- "not unknown_result.stdout"
|
||||
- "unknown_result.stderr" # An unknown command displays error on stderr.
|
||||
- "unknown_result|failed"
|
||||
- "not unknown_result|changed"
|
||||
@ -0,0 +1,2 @@
|
||||
@ECHO OFF
|
||||
ECHO We can even run a batch file!
|
||||
@ -0,0 +1,2 @@
|
||||
# Test script to make sure the Ansible script module works.
|
||||
Write-Host "Woohoo! We can run a PowerShell script via Ansible!"
|
||||
@ -0,0 +1,7 @@
|
||||
# Test script to make sure the Ansible script module works when arguments are
|
||||
# passed to the script.
|
||||
|
||||
foreach ($i in $args)
|
||||
{
|
||||
Write-Host $i;
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
# http://stackoverflow.com/questions/9948517/how-to-stop-a-powershell-script-on-the-first-error
|
||||
#$ErrorActionPreference = "Stop";
|
||||
# http://stackoverflow.com/questions/15777492/why-are-my-powershell-exit-codes-always-0
|
||||
|
||||
trap
|
||||
{
|
||||
Write-Error -ErrorRecord $_
|
||||
exit 1;
|
||||
}
|
||||
|
||||
throw "Oh noes I has an error"
|
||||
@ -0,0 +1,59 @@
|
||||
---
|
||||
|
||||
- name: run simple test script
|
||||
script: test_script.ps1
|
||||
register: test_script_result
|
||||
|
||||
- name: check that script ran
|
||||
assert:
|
||||
that:
|
||||
- "test_script_result.rc == 0"
|
||||
- "test_script_result.stdout"
|
||||
- "'Woohoo' in test_script_result.stdout"
|
||||
- "not test_script_result.stderr"
|
||||
- "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
|
||||
register: test_script_with_args_result
|
||||
|
||||
- name: check that script ran and received arguments
|
||||
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'"
|
||||
- "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 has errors
|
||||
script: test_script_with_errors.ps1
|
||||
register: test_script_with_errors_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: check that script ran but failed with errors
|
||||
assert:
|
||||
that:
|
||||
- "test_script_with_errors_result.rc != 0"
|
||||
- "not test_script_with_errors_result.stdout"
|
||||
- "test_script_with_errors_result.stderr"
|
||||
- "test_script_with_errors_result|failed"
|
||||
- "test_script_with_errors_result|changed"
|
||||
|
||||
- name: run simple batch file
|
||||
script: test_script.bat
|
||||
register: test_batch_result
|
||||
|
||||
- name: check that batch file ran
|
||||
assert:
|
||||
that:
|
||||
- "test_batch_result.rc == 0"
|
||||
- "test_batch_result.stdout"
|
||||
- "'batch' in test_batch_result.stdout"
|
||||
- "not test_batch_result.stderr"
|
||||
- "not test_batch_result|failed"
|
||||
- "test_batch_result|changed"
|
||||
@ -0,0 +1,8 @@
|
||||
---
|
||||
|
||||
- hosts: windows
|
||||
gather_facts: false
|
||||
roles:
|
||||
- { role: test_win_raw, tags: test_win_raw }
|
||||
- { role: test_win_script, tags: test_win_script }
|
||||
- { role: test_win_ping, tags: test_win_ping }
|
||||
Loading…
Reference in New Issue