Debian Codegraph @

ansible_collections/community/windows/tests/integration/targets/win_psexec/tasks/main.yml

raw
1 # Would use [] but this has troubles with PATH and trying to find the executable so just resort to keeping a space
2 - name: record special path for tests
3 set_fact:
4 testing_dir: '{{ remote_tmp_dir }}\ansible win_psexec'
5
6 - name: create special path testing dir
7 ansible.windows.win_file:
8 path: '{{ testing_dir }}'
9 state: directory
10
11 - name: Download PsExec
12 ansible.windows.win_get_url:
13 url: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/win_psexec/PsExec.exe
14 dest: '{{ testing_dir }}\PsExec.exe'
15 register: download_res
16 until: download_res is successful
17 retries: 3
18 delay: 5
19
20 - name: Get the existing PATH env var
21 ansible.windows.win_shell: '$env:PATH'
22 register: system_path
23 changed_when: False
24
25 - name: Run whoami
26 win_psexec:
27 command: whoami.exe
28 nobanner: true
29 register: whoami
30 environment:
31 PATH: '{{ testing_dir }};{{ system_path.stdout | trim }}'
32
33 - name: Test whoami
34 assert:
35 that:
36 - whoami.rc == 0
37 - whoami.stdout == ''
38 # FIXME: Standard output does not work or is truncated
39 #- whoami.stdout == '{{ ansible_hostname|lower }}'
40
41 - name: Run whoami as SYSTEM
42 win_psexec:
43 command: whoami.exe
44 system: yes
45 nobanner: true
46 executable: '{{ testing_dir }}\PsExec.exe'
47 register: whoami_as_system
48 # Seems to be a bug with PsExec where the stdout can be empty, just retry the task to make this test a bit more stable
49 until: whoami_as_system.rc == 0 and whoami_as_system.stdout == 'nt authority\system'
50 retries: 3
51 delay: 2
52
53 # FIXME: Behaviour is not consistent on all Windows systems
54 #- name: Run whoami as ELEVATED
55 # win_psexec:
56 # command: whoami.exe
57 # elevated: yes
58 # register: whoami_as_elevated
59 #
60 ## Ensure we have basic facts
61 #- ansible.windows.setup:
62 #
63 #- debug:
64 # msg: '{{ whoami_as_elevated.stdout|lower }} == {{ ansible_hostname|lower }}\{{ ansible_user_id|lower }}'
65 #
66 #- name: Test whoami
67 # assert:
68 # that:
69 # - whoami_as_elevated.rc == 0
70 # - whoami_as_elevated.stdout|lower == '{{ ansible_hostname|lower }}\{{ ansible_user_id|lower }}'
71
72 - name: Run command with multiple arguments
73 win_psexec:
74 command: powershell.exe -NonInteractive "exit 1"
75 ignore_errors: yes
76 register: whoami_multiple_args
77 environment:
78 PATH: '{{ testing_dir }};{{ system_path.stdout | trim }}'
79
80 - name: Test command with multiple argumetns
81 assert:
82 that:
83 - whoami_multiple_args.rc == 1
84 - whoami_multiple_args.psexec_command == "psexec.exe -accepteula powershell.exe -NonInteractive \"exit 1\""
85
86 - name: Run command with password
87 win_psexec:
88 command: whoami.exe
89 username: fake_user
90 password: '{{ item }}'
91 executable: '{{ testing_dir }}\PsExec.exe'
92 ignore_errors: yes # The username/password isn't valid so it will fail
93 loop:
94 - Testing123
95 - Testing"123 # This makes sure the escaped password for the cmd is also masked
96 register: psexec_pass
97
98 - name: Test password not in psexec_command output
99 assert:
100 that:
101 - psexec_pass.results[0].psexec_command.endswith("-u fake_user -p *PASSWORD_REPLACED* -accepteula whoami.exe")
102 - psexec_pass.results[1].psexec_command.endswith("-u fake_user -p *PASSWORD_REPLACED* -accepteula whoami.exe")