Debian Codegraph @

test/integration/targets/powershell_exec_wrapper/tasks/main.yml

raw
1 ---
2 - name: sample config for traceback behavior
3 set_fact:
4 traceback_on_error: |
5 {{ lookup('ansible._protomatter.config', 'DISPLAY_TRACEBACK') is contains 'error' }}
6
7 - name: fetch host information
8 get_info:
9 register: test_host_info
10
11 - name: test normal module execution
12 test_fail:
13 register: normal
14
15 - name: assert test normal module execution
16 assert:
17 that:
18 - not normal is failed
19
20 - name: test exec_wrapper with async
21 test_fail:
22 async: 60
23 poll: 5
24
25 - name: test out Windows specific exec wrapper tests
26 include_tasks: windows.yml
27 when: test_host_info.is_windows
28
29 - name: test fail module execution
30 test_fail:
31 data: fail
32 register: fail_module
33 ignore_errors: yes
34
35 - name: assert test fail module execution
36 assert:
37 that:
38 - fail_module is failed
39 - fail_module.msg == "fail message"
40 - fail_module.exception is defined
41
42 - name: test module with exception thrown
43 test_fail:
44 data: throw
45 register: throw_module
46 ignore_errors: yes
47
48 - name: assert test module with exception thrown
49 assert:
50 that:
51 - throw_module is failed
52 - 'throw_module.msg == "Unhandled exception while executing module: module is thrown"'
53 - not traceback_on_error or "throw [ArgumentException]\"module is thrown\"" in throw_module.exception
54 - not traceback_on_error or throw_module.exception is search "at <ScriptBlock>, ansible.legacy.test_fail.ps1. line 47"
55
56 - name: test module with error msg
57 test_fail:
58 data: error
59 register: error_module
60 ignore_errors: yes
61 vars:
62 # Running with coverage means the module is run from a script and not as a pseudo script in a pipeline. This
63 # results in a different error message being returned so we disable coverage collection for this task.
64 _ansible_coverage_remote_output: ''
65
66 - name: assert test module with error msg
67 assert:
68 that:
69 - error_module is failed
70 - 'error_module.msg == "Unhandled exception while executing module: error"'
71 - not traceback_on_error or "Write-Error -Message $data" in error_module.exception
72
73 - name: test module with cmdlet error
74 test_fail:
75 data: cmdlet_error
76 register: cmdlet_error
77 ignore_errors: yes
78
79 - name: assert test module with cmdlet error
80 assert:
81 that:
82 - cmdlet_error is failed
83 - 'cmdlet_error.msg == "Unhandled exception while executing module: Cannot find drive. A drive with the name ''fake'' does not exist."'
84 - not traceback_on_error or "Get-Item -Path \"fake:\\path\"" in cmdlet_error.exception
85
86 - name: test module with .NET exception
87 test_fail:
88 data: dotnet_exception
89 register: dotnet_exception
90 ignore_errors: yes
91
92 - name: assert test module with .NET exception
93 assert:
94 that:
95 - dotnet_exception is failed
96 - 'dotnet_exception.msg is contains("Unhandled exception while executing module: Exception calling \"GetFullPath\" with \"1\" argument(s): ")'
97 - not traceback_on_error or "[System.IO.Path]::GetFullPath($null)" in dotnet_exception.exception
98
99 - name: test module with function exception
100 test_fail:
101 data: function_throw
102 register: function_exception
103 ignore_errors: yes
104 vars:
105 _ansible_coverage_remote_output: ''
106
107 - name: assert test module with function exception
108 assert:
109 that:
110 - function_exception is failed
111 - 'function_exception.msg == "Unhandled exception while executing module: exception in function"'
112 - 'not traceback_on_error or "throw \"exception in function\"" in function_exception.exception'
113 - 'not traceback_on_error or "at Test-ThrowException, ansible.legacy.test_fail.ps1: line" in function_exception.exception'
114
115 - name: test module with fail process but Exit-Json
116 test_fail:
117 data: proc_exit_fine
118 register: proc_exit_fine
119
120 - name: assert test module with fail process but Exit-Json
121 assert:
122 that:
123 - not proc_exit_fine is failed
124
125 - name: test module with fail process but Fail-Json
126 test_fail:
127 data: proc_exit_fail
128 register: proc_exit_fail
129 ignore_errors: yes
130
131 - name: assert test module with fail process but Fail-Json
132 assert:
133 that:
134 - proc_exit_fail is failed
135 - proc_exit_fail.msg == "proc_exit_fail"
136 - proc_exit_fail.exception is defined
137
138 - name: test out invalid options
139 test_invalid_requires:
140 register: invalid_options
141
142 - name: assert test out invalid options
143 assert:
144 that:
145 - invalid_options is successful
146 - invalid_options.output == "output"
147
148 - name: test out invalid powershell version
149 test_min_ps_version:
150 register: invalid_ps_version
151 ignore_errors: yes
152
153 - name: assert test out invalid powershell version
154 assert:
155 that:
156 - invalid_ps_version is failed
157 - '"This module cannot run as it requires a minimum PowerShell version of 20.0.0.0, actual was " in invalid_ps_version.msg'
158
159 - name: define common environment variables for all tasks
160 set_fact:
161 common_env_ars:
162 String: string value
163 Int: 1234
164 Bool: True
165 double_quote: 'double " quote'
166 single_quote: "single ' quote"
167
168 - name: define Windows specific environment variables
169 set_fact:
170 windows_env_ars:
171 hyphen-var: abc@123
172 '_-(){}[]<>*+-/\?"''!@#$%^&|;:i,.`~0': '_-(){}[]<>*+-/\?"''!@#$%^&|;:i,.`~0'
173 '‘key': 'value‚'
174
175 # These env vars don't work with the shell inline commands so we only test
176 # them with Windows.
177 - name: test out environment block for task
178 get_env:
179 environment: '{{ common_env_ars | combine(windows_env_ars if test_host_info.is_windows else {}) }}'
180 register: environment_block
181
182 - name: test out environment block for task with async
183 get_env:
184 environment: '{{ common_env_ars | combine(windows_env_ars if test_host_info.is_windows else {}) }}'
185 register: environment_block_async
186 async: 60
187 poll: 5
188
189 - name: assert environment block for task
190 assert:
191 that:
192 - '"String=string value" in environment_block.env_vars'
193 - '"String=string value" in environment_block_async.env_vars'
194 - '"Int=1234" in environment_block.env_vars'
195 - '"Int=1234" in environment_block_async.env_vars'
196 - '"Bool=True" in environment_block.env_vars'
197 - '"Bool=True" in environment_block_async.env_vars'
198 - '"double_quote=double \" quote" in environment_block.env_vars'
199 - '"double_quote=double \" quote" in environment_block_async.env_vars'
200 - '"single_quote=single '' quote" in environment_block.env_vars'
201 - '"single_quote=single '' quote" in environment_block_async.env_vars'
202
203 - name: assert environment block for task on Windows
204 assert:
205 that:
206 - '"hyphen-var=abc@123" in environment_block.env_vars'
207 - '"hyphen-var=abc@123" in environment_block_async.env_vars'
208 # yaml escaping rules - (\\ == \), (\" == "), ('' == ')
209 - '"_-(){}[]<>*+-/\\?\"''!@#$%^&|;:i,.`~0=_-(){}[]<>*+-/\\?\"''!@#$%^&|;:i,.`~0" in environment_block.env_vars'
210 - '"_-(){}[]<>*+-/\\?\"''!@#$%^&|;:i,.`~0=_-(){}[]<>*+-/\\?\"''!@#$%^&|;:i,.`~0" in environment_block_async.env_vars'
211 - '"‘key=value‚" in environment_block.env_vars'
212 - '"‘key=value‚" in environment_block_async.env_vars'
213 when: test_host_info.is_windows
214
215 - name: test module that sets HadErrors with no error records
216 test_rc_1:
217 register: module_had_errors
218
219 - name: assert test module that sets HadErrors with no error records
220 assert:
221 that:
222 - module_had_errors.rc == 0
223
224 - name: test module cannot access exec wrapper scope
225 test_exec_wrapper_scope:
226 register: exec_wrapper_scope
227
228 - name: assert test module cannot access exec wrapper scope
229 assert:
230 that:
231 - exec_wrapper_scope.module_using_namespace == 'System.Management.Automation.Language.Parser'
232 - exec_wrapper_scope.missing_using_namespace == True
233 - exec_wrapper_scope.script_var == 'foo'
234 - exec_wrapper_scope.util_res.module_using_namespace == 'System.Security.Cryptography.X509Certificates.X509Certificate2'
235 - exec_wrapper_scope.util_res.missing_using_namespace == True
236 - exec_wrapper_scope.util_res.script_var == 'bar'
237
238 - name: test module without any util references
239 test_no_utils:
240 foo: bar
241 register: no_utils_res
242
243 - name: assert test module without any util references
244 assert:
245 that:
246 - no_utils_res is not changed
247 - no_utils_res.complex_args['foo'] == 'bar'
248
249 - name: test module with invalid syntax
250 test_invalid_syntax:
251 register: invalid_syntax
252 ignore_errors: true
253
254 - name: assert test module with invalid syntax
255 assert:
256 that:
257 - invalid_syntax is failed
258 - invalid_syntax.msg is contains("Failed to parse script 'ansible.legacy.test_invalid_syntax.ps1'")
259
260 - name: test module with invalid module_util syntax
261 test_invalid_util_syntax:
262 register: invalid_util_syntax
263 ignore_errors: true
264
265 - name: assert test module with invalid module_util syntax
266 assert:
267 that:
268 - invalid_util_syntax is failed
269 - invalid_util_syntax.msg is contains("Failed to parse script 'Ansible.ModuleUtils.InvalidSyntax.psm1'")
270
271 - name: check if pipelining is supported on connection
272 set_fact:
273 connection_pipelining: |
274 {{ lookup('config', 'pipelining', plugin_type='connection', plugin_name=ansible_connection, on_missing='skip') }}
275
276 # Needs to be define outside the block, will emit a warning
277 # if the block gets skipped as the name for each task fails templating
278 - name: determine if next tests are with or without pipelining
279 set_fact:
280 operation: '{{ connection_pipelining | ternary("without", "with") }}'
281
282 - when: connection_pipelining != [] # on_missing='skip' results in []
283 block:
284 - name: run pwsh module {{ operation }} pipelining
285 test_fail:
286 vars:
287 ansible_pipelining: '{{ not connection_pipelining }}'
288
289 - name: run async pwsh module {{ operation }} pipelining
290 test_fail:
291 async: 60
292 poll: 5
293 vars:
294 ansible_pipelining: '{{ not connection_pipelining }}'