Debian Codegraph @

test/integration/targets/windows-minimal/tasks/main.yml

raw
1 # test code for the win_ping module
2 # (c) 2014, Chris Church <[email protected]>
3
4 # This file is part of Ansible
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18
19 - name: sample config for traceback behavior
20 set_fact:
21 traceback_on_error: |
22 {{ lookup('ansible._protomatter.config', 'DISPLAY_TRACEBACK') is contains 'error' }}
23
24 - name: test win_ping
25 action: win_ping
26 register: win_ping_result
27
28 - name: check win_ping result
29 assert:
30 that:
31 - win_ping_result is not failed
32 - win_ping_result is not changed
33 - win_ping_result.ping == 'pong'
34
35 - name: test win_ping with data
36 win_ping:
37 data: ☠
38 register: win_ping_with_data_result
39
40 - name: check win_ping result with data
41 assert:
42 that:
43 - win_ping_with_data_result is not failed
44 - win_ping_with_data_result is not changed
45 - win_ping_with_data_result.ping == '☠'
46
47 - name: test win_ping.ps1 with data as complex args
48 # win_ping.ps1: # TODO: do we want to actually support this? no other tests that I can see...
49 win_ping:
50 data: bleep
51 register: win_ping_ps1_result
52
53 - name: check win_ping.ps1 result with data
54 assert:
55 that:
56 - win_ping_ps1_result is not failed
57 - win_ping_ps1_result is not changed
58 - win_ping_ps1_result.ping == 'bleep'
59
60 - name: test win_ping using data=crash so that it throws an exception
61 win_ping:
62 data: crash
63 register: win_ping_crash_result
64 ignore_errors: yes
65
66 - name: check win_ping_crash result
67 assert:
68 that:
69 - win_ping_crash_result is failed
70 - win_ping_crash_result is not changed
71 - 'win_ping_crash_result.msg == "Unhandled exception while executing module: boom"'
72 - not traceback_on_error or "throw \"boom\"" in win_ping_crash_result.exception
73
74 - name: verify that shortname _raw_params works
75 win_shell: echo "name=foo"
76 register: win_shell_short_res
77 failed_when: win_shell_short_res.stdout | trim != 'name=foo'
78
79 - name: verify that legacy _raw_params works
80 ansible.legacy.win_shell: echo "name=foo"
81 register: win_shell_legacy_res
82 failed_when: win_shell_legacy_res.stdout | trim != 'name=foo'
83
84 - name: verify that builtin _raw_params works
85 ansible.builtin.win_shell: echo "name=foo"
86 register: win_shell_builtin_res
87 failed_when: win_shell_builtin_res.stdout | trim != 'name=foo'
88
89 - name: verify that collection _raw_params works
90 ansible.windows.win_shell: echo "name=foo"
91 register: win_shell_collection_res
92 failed_when: win_shell_collection_res.stdout | trim != 'name=foo'
93
94 - name: set ping data fact
95 set_fact:
96 # FUTURE: Fix psrp so it can handle non-ASCII chars in a non-pipeline scenario
97 ping_data: '{{ (ansible_connection == "psrp") | ternary("test", "汉语") }}'
98
99 - name: run module with pipelining disabled
100 ansible.builtin.command:
101 cmd: >-
102 ansible windows
103 -m ansible.windows.win_ping
104 -a 'data={{ ping_data }}'
105 -i {{ '-i '.join(ansible_inventory_sources) }}
106 {{ '' if not ansible_verbosity else '-' ~ ('v' * ansible_verbosity) }}
107 -e ansible_remote_tmp='{{ remote_tmp_dir | regex_replace('\\', '\\\\') }}'
108 register: pipeline_disabled_res
109 delegate_to: localhost
110 environment:
111 ANSIBLE_KEEP_REMOTE_FILES: 'true'
112 ANSIBLE_NOCOLOR: 'true'
113 ANSIBLE_FORCE_COLOR: 'false'
114
115 - name: view temp files
116 ansible.windows.win_shell: (Get-Item '{{ remote_tmp_dir }}\ansible-tmp-*\*').Name
117 register: pipeline_disabled_files
118
119 - name: assert run module with pipelining disabled
120 assert:
121 that:
122 - >-
123 pipeline_disabled_res.stdout is search('\"ping\": \"' ~ ping_data ~ '\"')
124 - pipeline_disabled_files.stdout_lines == ["AnsiballZ_win_ping.ps1"]
125
126 - name: test module with no exec wrapper
127 test_no_exec_wrapper:
128 register: no_exec_wrapper
129
130 - name: assert test module with no exec wrapper
131 assert:
132 that:
133 - no_exec_wrapper is not failed
134 - no_exec_wrapper.args | length == 1
135 - '"_ansible_check_mode=False" in no_exec_wrapper.arg0'
136 - no_exec_wrapper.path != ""
137
138 - name: check if the script and args file still exist
139 win_stat:
140 path: '{{ item }}'
141 register: no_exec_wrapper_files
142 loop:
143 - '{{ no_exec_wrapper.path }}'
144 - '{{ no_exec_wrapper.args[0] }}'
145
146 - name: assert no exec wrapper files still exist
147 assert:
148 that:
149 - no_exec_wrapper_files.results | map(attribute='stat.exists') | list == [False, False]