Debian Codegraph @

ansible_collections/community/windows/tests/integration/targets/psexec/tasks/tests.yml

raw
1 ---
2 - name: fail when process_password is not set with process_username
3 psexec:
4 hostname: '{{psexec_hostname}}'
5 connection_username: '{{psexec_username}}'
6 connection_password: '{{psexec_password}}'
7 encrypt: '{{psexec_encrypt}}'
8 executable: hostname.exe
9 process_username: '{{psexec_username}}'
10 delegate_to: localhost
11 register: fail_no_process_pass
12 failed_when: 'fail_no_process_pass.msg != "parameters are required together when not running as System: process_username, process_password"'
13
14 - name: get current host
15 ansible.windows.win_command: hostname.exe
16 register: actual_hostname
17
18 - name: run basic psexec command
19 psexec:
20 hostname: '{{psexec_hostname}}'
21 connection_username: '{{psexec_username}}'
22 connection_password: '{{psexec_password}}'
23 encrypt: '{{psexec_encrypt}}'
24 executable: hostname.exe
25 delegate_to: localhost
26 register: psexec_hostname_actual
27
28 - name: assert basic psexec command matches expected output
29 assert:
30 that:
31 - psexec_hostname_actual is changed
32 - psexec_hostname_actual.rc == 0
33 - psexec_hostname_actual.stderr == ''
34 - psexec_hostname_actual.stdout == actual_hostname.stdout
35
36 - name: get output for executable with arguments
37 ansible.windows.win_command: hostname.exe /?
38 register: actual_hostname_help
39 failed_when: actual_hostname_help.rc != 1
40
41 - name: run psexec command with arguments
42 psexec:
43 hostname: '{{psexec_hostname}}'
44 connection_username: '{{psexec_username}}'
45 connection_password: '{{psexec_password}}'
46 encrypt: '{{psexec_encrypt}}'
47 executable: hostname.exe
48 arguments: /?
49 delegate_to: localhost
50 register: psexec_hostname_help
51 failed_when: psexec_hostname_help.rc != 1
52
53 - name: assert basic pesexec command with arguments matches expected output
54 assert:
55 that:
56 - psexec_hostname_help is changed
57 - psexec_hostname_help.rc == 1
58 - psexec_hostname_help.stderr == actual_hostname_help.stderr
59 - psexec_hostname_help.stdout == actual_hostname_help.stdout
60
61 - name: run psexec command and send data through stdin
62 psexec:
63 hostname: '{{psexec_hostname}}'
64 connection_username: '{{psexec_username}}'
65 connection_password: '{{psexec_password}}'
66 encrypt: '{{psexec_encrypt}}'
67 executable: powershell.exe
68 arguments: '-'
69 stdin: |
70 Write-Host hello world
71 Write-Host this is another message
72 exit 0
73 delegate_to: localhost
74 register: psexec_stdin
75
76 - name: assert psexec ommand and send data through stdin
77 assert:
78 that:
79 - psexec_stdin is changed
80 - psexec_stdin.rc == 0
81 - psexec_stdin.stderr == ''
82 - psexec_stdin.stdout == 'hello world\nthis is another message\n'
83
84 - name: run psexec command with specific process username
85 psexec:
86 hostname: '{{psexec_hostname}}'
87 connection_username: '{{psexec_username}}'
88 connection_password: '{{psexec_password}}'
89 encrypt: '{{psexec_encrypt}}'
90 load_profile: no # on Azure, the profile does not exist yet so we don't load it for this task
91 executable: powershell.exe
92 arguments: '-'
93 stdin: |
94 ((Get-CimInstance Win32_Process -filter "processid = $pid") | Get-CimAssociatedInstance -Association Win32_SessionProcess).LogonType
95 exit 0
96 process_username: '{{psexec_username}}'
97 process_password: '{{psexec_password}}'
98 delegate_to: localhost
99 register: psexec_process_username
100
101 - name: assert psexec command with specific process username
102 assert:
103 that:
104 - psexec_process_username is changed
105 - psexec_process_username.rc == 0
106 - psexec_process_username.stderr == ''
107 - psexec_process_username.stdout_lines[0] != '3' # 3 is Network Logon Type, we assert we are not a network logon with process credentials
108
109 - name: run psexec command with both stderr and stdout
110 psexec:
111 hostname: '{{psexec_hostname}}'
112 connection_username: '{{psexec_username}}'
113 connection_password: '{{psexec_password}}'
114 encrypt: '{{psexec_encrypt}}'
115 executable: cmd.exe
116 arguments: /c echo first && echo second 1>&2 && echo third
117 delegate_to: localhost
118 register: psexec_process_stderr
119
120 - name: assert psexec command with both stderr and stdout
121 assert:
122 that:
123 - psexec_process_stderr is changed
124 - psexec_process_stderr.rc == 0
125 - psexec_process_stderr.stderr == 'second \r\n'
126 - psexec_process_stderr.stdout == 'first \r\nthird\r\n'
127
128 - name: run process asynchronously
129 psexec:
130 hostname: '{{psexec_hostname}}'
131 connection_username: '{{psexec_username}}'
132 connection_password: '{{psexec_password}}'
133 encrypt: '{{psexec_encrypt}}'
134 executable: powershell.exe
135 arguments: Start-Sleep -Seconds 30
136 asynchronous: yes
137 delegate_to: localhost
138 register: psexec_process_async
139
140 - name: check if process is still running
141 ansible.windows.win_shell: (Get-Process -ID {{psexec_process_async.pid}}).ProcessName
142 register: psexec_process_async_actual
143
144 - name: assert run process asynchronously
145 assert:
146 that:
147 - psexec_process_async is changed
148 - psexec_process_async.rc is not defined
149 - psexec_process_async.pid is defined
150 - psexec_process_async.stdout is not defined
151 - psexec_process_async.stderr is not defined
152 - psexec_process_async_actual.stdout_lines[0] == 'powershell'
153
154 - name: run process interactively
155 psexec:
156 hostname: '{{psexec_hostname}}'
157 connection_username: '{{psexec_username}}'
158 connection_password: '{{psexec_password}}'
159 encrypt: '{{psexec_encrypt}}'
160 executable: powershell.exe
161 arguments: Write-Host hi
162 interactive: yes
163 delegate_to: localhost
164 register: psexec_process_interactive
165
166 - name: assert run process interactively
167 assert:
168 that:
169 - psexec_process_interactive is changed
170 - psexec_process_interactive.rc == 0
171 - psexec_process_interactive.stdout is not defined
172 - psexec_process_interactive.stderr is not defined
173
174 - name: run process with timeout
175 psexec:
176 hostname: '{{psexec_hostname}}'
177 connection_username: '{{psexec_username}}'
178 connection_password: '{{psexec_password}}'
179 encrypt: '{{psexec_encrypt}}'
180 executable: powershell.exe
181 arguments: Start-Sleep -Seconds 30
182 process_timeout: 5
183 delegate_to: localhost
184 register: psexec_process_timeout
185 failed_when: psexec_process_timeout.rc == 0
186
187 - name: assert psexec process with timeout
188 assert:
189 that:
190 - psexec_process_timeout.rc != 0
191 - psexec_process_timeout.stdout == ''
192 - psexec_process_timeout.stderr == ''
193
194 - name: run process as system
195 psexec:
196 hostname: '{{psexec_hostname}}'
197 connection_username: '{{psexec_username}}'
198 connection_password: '{{psexec_password}}'
199 encrypt: '{{psexec_encrypt}}'
200 executable: whoami.exe
201 process_username: System
202 delegate_to: localhost
203 register: psexec_process_system
204
205 - name: assert run process as system
206 assert:
207 that:
208 - psexec_process_system is changed
209 - psexec_process_system.rc == 0
210 - psexec_process_system.stderr == ''
211 - psexec_process_system.stdout == 'nt authority\system\r\n'
212
213 - name: run process with different chdir
214 psexec:
215 hostname: '{{psexec_hostname}}'
216 connection_username: '{{psexec_username}}'
217 connection_password: '{{psexec_password}}'
218 encrypt: '{{psexec_encrypt}}'
219 executable: powershell.exe
220 arguments: (pwd).Path
221 working_directory: C:\Windows
222 delegate_to: localhost
223 register: psexec_process_working_dir
224
225 - name: assert run process with different chdir
226 assert:
227 that:
228 - psexec_process_working_dir is changed
229 - psexec_process_working_dir.rc == 0
230 - psexec_process_working_dir.stderr == ''
231 - psexec_process_working_dir.stdout == 'C:\Windows\r\n'