From b044bb431e9e594abf83584d2c47ba35fb85bf6f Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Wed, 13 Mar 2019 12:26:59 +1000 Subject: [PATCH] Use shared remote_tmp_dir to simplfy tests (#53721) --- .../targets/win_psexec/meta/main.yml | 2 + .../targets/win_psexec/tasks/main.yml | 49 +++++-------------- 2 files changed, 14 insertions(+), 37 deletions(-) create mode 100644 test/integration/targets/win_psexec/meta/main.yml diff --git a/test/integration/targets/win_psexec/meta/main.yml b/test/integration/targets/win_psexec/meta/main.yml new file mode 100644 index 0000000000..9f37e96cd9 --- /dev/null +++ b/test/integration/targets/win_psexec/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: +- setup_remote_tmp_dir diff --git a/test/integration/targets/win_psexec/tasks/main.yml b/test/integration/targets/win_psexec/tasks/main.yml index a09401ccff..655c9bffae 100644 --- a/test/integration/targets/win_psexec/tasks/main.yml +++ b/test/integration/targets/win_psexec/tasks/main.yml @@ -1,31 +1,20 @@ -- name: Download PSTools +- name: Download PsExec win_get_url: - url: https://download.sysinternals.com/files/PSTools.zip - dest: C:\Windows\Temp\PSTools.zip - force: no + url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/win_psexec/PsExec.exe + dest: '{{ remote_tmp_dir }}\PsExec.exe' -- name: Create sysinternals directory - win_file: - path: C:\Windows\Temp\sysinternals - state: directory - -- name: Unzip PSTools - win_unzip: - src: C:\Windows\Temp\PSTools.zip - dest: C:\Windows\Temp\sysinternals - -- name: Add sysinternals to PATH - win_path: - name: PATH - elements: C:\Windows\Temp\sysinternals - scope: machine - state: present +- name: Get the existing PATH env var + win_shell: '$env:PATH' + register: system_path + changed_when: False - name: Run whoami win_psexec: command: whoami.exe nobanner: true register: whoami + environment: + PATH: '{{ remote_tmp_dir }};{{ system_path.stdout | trim }}' - name: Test whoami assert: @@ -40,6 +29,7 @@ command: whoami.exe system: yes nobanner: true + executable: '{{ remote_tmp_dir }}\PsExec.exe' register: whoami_as_system # 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 until: whoami_as_system.rc == 0 and whoami_as_system.stdout == 'nt authority\system' @@ -70,26 +60,11 @@ command: powershell.exe -NonInteractive "exit 1" ignore_errors: yes register: whoami_multiple_args + environment: + PATH: '{{ remote_tmp_dir }};{{ system_path.stdout | trim }}' - name: Test command with multiple argumetns assert: that: - whoami_multiple_args.rc == 1 - whoami_multiple_args.psexec_command == "psexec.exe -accepteula powershell.exe -NonInteractive \"exit 1\"" - -- name: Remove sysinternals from PATH - win_path: - name: PATH - elements: C:\Windows\Temp\sysinternals - scope: machine - state: absent - -- name: Remove sysinternals directory - win_file: - path: C:\Windows\Temp\sysinternals - state: absent - -- name: Remove sysinternals directory - win_file: - path: C:\Windows\Temp\PSTools.zip - state: absent