ansible/test/integration/targets/win_package/tasks/msi_tests.yml
Jordan Borean 446a0c1b08
win_package - Refactor with msp, appx support (#66931)
* win_package - Refactor with msp, appx support

* Added msi test for ALLUSERS

* Added some msix tests, refactored tests

* Added remaining msix tests

* Enable msix sideloading for tests

* Added remaining exe path tests

* Added basic msp tests

* Remove url options now the util no longer has them

* Fix file version check for older Windows hosts

* Remove no_proxy ansible-test setting

* Use same mechanism of become to copy the file with explicit creds
2020-02-13 16:44:19 +10:00

511 lines
16 KiB
YAML

---
# this test just makes sure the task doesn't fail when we set out expected rc
- name: install broken msi override expected rc
win_package:
path: '{{ test_path }}\bad.msi'
state: present
expected_return_code: 0,1603
- name: install local msi (check mode)
win_package:
path: '{{ test_path }}\good.msi'
state: present
register: install_local_msi_check
check_mode: yes
- name: get result of install local msi (check mode)
win_reg_stat:
path: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ good_id }}
register: install_local_msi_actual_check
- name: assert install local msi (check mode)
assert:
that:
- install_local_msi_check is changed
- install_local_msi_check.reboot_required == False
- install_local_msi_actual_check.exists == False
- name: install local msi with log
win_package:
path: '{{ test_path }}\good.msi'
state: present
log_path: '{{ test_path }}\msi.log'
register: install_local_msi
- name: get result of install local msi
win_reg_stat:
path: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ good_id }}
register: install_local_msi_actual
- name: assert install local msi
assert:
that:
- install_local_msi is changed
- install_local_msi.reboot_required == False
- install_local_msi.rc == 0
- install_local_msi_actual.exists == True
- name: get result of install local msi log_path
win_stat:
path: '{{ test_path }}\msi.log'
register: install_local_msi_actual_log_path
- name: assert install local msi log path
assert:
that:
- install_local_msi_actual_log_path.stat.exists == True
- name: install local msi (idempotent)
win_package:
path: '{{ test_path }}\good.msi'
state: present
register: install_local_msi_idempotent
- name: assert install local msi (idempotent)
assert:
that:
- install_local_msi_idempotent is not changed
- name: uninstall local msi with path (check mode)
win_package:
path: '{{ test_path }}\good.msi'
state: absent
register: uninstall_path_local_msi_check
check_mode: yes
- name: get result of uninstall local msi with path (check mode)
win_reg_stat:
path: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ good_id }}
register: uninstall_path_local_msi_actual_check
- name: assert uninstall local msi with path (check mode)
assert:
that:
- uninstall_path_local_msi_check is changed
- uninstall_path_local_msi_check.reboot_required == False
- uninstall_path_local_msi_actual_check.exists == True
- name: uninstall local msi with path
win_package:
path: '{{ test_path }}\good.msi'
state: absent
log_path: '{{ test_path }}\msi uninstall.log'
register: uninstall_path_local_msi
- name: get result of uninstall local msi with path
win_reg_stat:
path: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ good_id }}
register: uninstall_path_local_msi_actual
- name: assert uninstall local msi with path
assert:
that:
- uninstall_path_local_msi is changed
- uninstall_path_local_msi.reboot_required == False
- uninstall_path_local_msi.rc == 0
- uninstall_path_local_msi_actual.exists == False
- name: get result of uninstall local msi with path
win_stat:
path: '{{ test_path }}\msi uninstall.log'
register: uninstall_path_local_msi_actual_log_path
- name: assert uninstall local msi with path
assert:
that:
- uninstall_path_local_msi_actual_log_path.stat.exists == True # we expect log to remain
- name: uninstall local msi with path (idempotent)
win_package:
path: '{{ test_path }}\good.msi'
state: absent
register: uninstall_path_local_msi_idempotent
- name: assert uninstall local msi with path (idempotent)
assert:
that:
- uninstall_path_local_msi_idempotent is not changed
- name: install url msi (check mode)
win_package:
path: '{{ good_url }}'
product_id: '{{ good_id }}'
state: present
register: install_url_msi_check
check_mode: yes
- name: get result of install url msi (check mode)
win_reg_stat:
path: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ good_id }}
register: install_url_msi_actual_check
- name: assert install url msi (check mode)
assert:
that:
- install_url_msi_check is changed
- install_url_msi_check.reboot_required == False
- install_url_msi_actual_check.exists == False
- name: install url msi
win_package:
path: '{{ good_url }}'
product_id: '{{ good_id }}'
state: present
register: install_url_msi
- name: get result of install url msi
win_reg_stat:
path: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ good_id }}
register: install_url_msi_actual
- name: assert install url msi
assert:
that:
- install_url_msi is changed
- install_url_msi.reboot_required == False
- install_url_msi.rc == 0
- install_url_msi_actual.exists == True
- name: install url msi (idempotent)
win_package:
path: '{{ good_url }}'
product_id: '{{ good_id }}'
state: present
register: install_url_msi_again
- name: assert install url msi (idempotent)
assert:
that:
- install_url_msi_again is not changed
- name: uninstall local msi with product_id (check mode)
win_package:
product_id: '{{ good_id }}'
state: absent
register: uninstall_id_local_msi_check
check_mode: yes
- name: get result of uninstall local msi with product_id (check mode)
win_reg_stat:
path: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ good_id }}
register: uninstall_id_local_msi_actual_check
- name: assert uninstall local msi with product_id (check mode)
assert:
that:
- uninstall_id_local_msi_check is changed
- uninstall_id_local_msi_check.reboot_required == False
- uninstall_id_local_msi_actual_check.exists == True
- name: uninstall local msi with product_id
win_package:
product_id: '{{ good_id }}'
state: absent
register: uninstall_id_local_msi
- name: get result of uninstall local msi with product_id
win_reg_stat:
path: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ good_id }}
register: uninstall_id_local_msi_actual
- name: assert uninstall local msi with product_id
assert:
that:
- uninstall_id_local_msi is changed
- uninstall_id_local_msi.reboot_required == False
- uninstall_id_local_msi.rc == 0
- uninstall_id_local_msi_actual.exists == False
- name: uninstall local msi with product_id (idempotent)
win_package:
product_id: '{{ good_id }}'
state: absent
register: uninstall_id_local_msi_idempotent
- name: assert uninstall local msi with product_id (idempotent)
assert:
that:
- uninstall_id_local_msi_idempotent is not changed
- name: install local reboot msi (check mode)
win_package:
path: '{{ test_path }}\reboot.msi'
state: present
register: install_local_reboot_msi_check
check_mode: yes
- name: get result of install local reboot msi (check mode)
win_reg_stat:
path: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ reboot_id }}
register: install_local_reboot_msi_actual_check
- name: assert install local reboot msi (check mode)
assert:
that:
- install_local_reboot_msi_check is changed
- install_local_reboot_msi_check.reboot_required == False
- install_local_reboot_msi_actual_check.exists == False
- name: install local reboot msi
win_package:
path: '{{ test_path }}\reboot.msi'
state: present
register: install_local_reboot_msi
- name: get result of install local reboot msi
win_reg_stat:
path: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{ reboot_id }}
register: install_local_reboot_msi_actual
- name: assert install local reboot msi
assert:
that:
- install_local_reboot_msi is changed
- install_local_reboot_msi.reboot_required == True
- install_local_reboot_msi.rc == 3010
- install_local_reboot_msi_actual.exists == True
- name: install local reboot msi (idempotent)
win_package:
path: '{{ test_path }}\reboot.msi'
state: present
register: install_local_reboot_msi_idempotent
- name: assert install local reboot msi (idempotent)
assert:
that:
- install_local_reboot_msi_idempotent is not changed
- name: uninstall reboot msi after test
win_package:
path: '{{ test_path }}\reboot.msi'
state: absent
- name: ensure the install folder is cleaned in case uninstall didn't work
win_file:
path: '%ProgramFiles(x86)%\Bovine University'
state: absent
- name: install local msi with arguments (check mode)
win_package:
path: '{{ test_path }}\good.MSI'
state: present
arguments: ADDLOCAL=Cow
register: install_msi_argument_check
check_mode: yes
- name: get result of moo file after install local msi with arguments (check mode)
win_stat:
path: '%ProgramFiles(x86)%\Bovine University\moo.exe'
register: install_msi_argument_moo_check
- name: get result of cow file after install local msi with arguments (check mode)
win_stat:
path: '%ProgramFiles(x86)%\Bovine University\cow.exe'
register: install_msi_argument_cow_check
- name: assert install local msi with arguments (check mode)
assert:
that:
- install_msi_argument_check is changed
- install_msi_argument_check.reboot_required == False
- install_msi_argument_moo_check.stat.exists == False
- install_msi_argument_cow_check.stat.exists == False
- name: install local msi with arguments
win_package:
path: '{{ test_path}}\good.MSI'
state: present
arguments: ADDLOCAL=Cow
register: install_msi_argument
- name: get result of moo file after install local msi with arguments
win_stat:
path: '%ProgramFiles(x86)%\Bovine University\moo.exe'
register: install_msi_argument_moo
- name: get result of cow file after install local msi with arguments
win_stat:
path: '%ProgramFiles(x86)%\Bovine University\cow.exe'
register: install_msi_argument_cow
- name: assert install local msi with arguments
assert:
that:
- install_msi_argument is changed
- install_msi_argument.reboot_required == False
- install_msi_argument.rc == 0
- install_msi_argument_moo.stat.exists == False
- install_msi_argument_cow.stat.exists == True
- name: install local msi with arguments (idempotent)
win_package:
path: '{{ test_path}}\good.MSI'
state: present
arguments: ADDLOCAL=Cow
register: install_msi_argument_again
- name: assert install local msi with arguments (idempotent)
assert:
that:
- install_msi_argument_again is not changed
- name: uninstall good msi after test
win_package:
path: '{{ test_path }}\good.msi'
state: absent
- name: install good msi for all users
win_package:
path: '{{ test_path }}\good.msi'
state: present
arguments: ALLUSERS=1
register: install_good_all_users
- name: get result of install good msi for all users
win_shell: |
Add-Type -Namespace Msi -Name NativeMethods -UsingNamespace System.Text -MemberDefinition @'
[DllImport("Msi.dll", CharSet = CharSet.Unicode)]
public static extern UInt32 MsiGetProductInfoExW(
string szProductCode,
string szUserSid,
UInt32 dwContext,
string szProperty,
StringBuilder szValue,
ref UInt32 pcchValue);
'@
$productCode = '{{ good_id }}'
$sb = New-Object -TypeName System.Text.StringBuilder -ArgumentList 0
$sbLength = [UInt32]0
$null = [Msi.NativeMethods]::MsiGetProductInfoExW($productCode, [NullString]::Value, 4, "State", $sb, [ref]$sbLength)
$sbLength += 1
$null = $sb.EnsureCapacity($sbLength)
$null = [Msi.NativeMethods]::MsiGetProductInfoExW($productCode, [NullString]::Value, 4, "State", $sb, [ref]$sbLength)
[int]$sb.ToString()
register: install_good_all_users_actual
- name: assert install good msi for all users
assert:
that:
- install_good_all_users is changed
- install_good_all_users_actual.stdout | trim | int == 5 # INSTALLSTATE_DEFAULT
- name: install good msi for all users (idempotent)
win_package:
path: '{{ test_path }}\good.msi'
state: present
arguments: ALLUSERS=1
register: install_good_all_users_again
- name: assert install good msi for all users (idempotent)
assert:
that:
- not install_good_all_users_again is changed
- name: uninstall good msi for all users
win_package:
product_id: '{{ good_id }}'
state: absent
register: uninstall_good_all_users
- name: get result of uninstall good msi for all users
win_shell: |
Add-Type -Namespace Msi -Name NativeMethods -MemberDefinition @'
[DllImport("Msi.dll", CharSet = CharSet.Unicode)]
public static extern Int32 MsiQueryProductStateW(
string szProductCode);
'@
[Msi.NativeMethods]::MsiQueryProductStateW('{{ good_id }}')
register: uninstall_good_all_users_actual
- name: assert uninstall good msi for all users
assert:
that:
- uninstall_good_all_users is changed
- uninstall_good_all_users_actual.stdout | trim | int == -1 # INSTALLSTATE_UNKNOWN
- name: create custom install directory for msi install
win_file:
path: '{{ test_path }}\msi install'
state: directory
- name: install msi to custom path using string arguments
win_package:
path: '{{ test_path }}\good.msi'
state: present
arguments: ADDLOCAL=Cow INSTALLDIR="{{ test_path }}\msi install"
register: install_msi_string_arguments
- name: get result of moo file after install local msi with string arguments
win_stat:
path: '{{ test_path }}\msi install\moo.exe'
register: install_msi_string_arguments_moo
- name: get result of cow file after install local msi with string arguments
win_stat:
path: '{{ test_path }}\msi install\cow.exe'
register: install_msi_string_arguments_cow
- name: assert results of install msi to custom path using string arguments
assert:
that:
- install_msi_string_arguments is changed
- install_msi_string_arguments.reboot_required == False
- install_msi_string_arguments.rc == 0
- install_msi_string_arguments_moo.stat.exists == False
- install_msi_string_arguments_cow.stat.exists == True
- name: uninstall good msi after string argument test
win_package:
path: '{{ test_path }}\good.msi'
state: absent
# MSI arguments KEY="value" are known to fail when set as a list, for this test just create a simple folder path that
# does not need to be escaped and cleanup at the end.
- name: create a simple spaceless folder for argument list test
win_file:
path: C:\ansible_win_package
state: directory
- block:
- name: install msi to custom path using list arguments
win_package:
path: '{{ test_path }}\good.msi'
state: present
arguments:
- ADDLOCAL=Moo
- INSTALLDIR=C:\ansible_win_package
register: install_msi_list_arguments
- name: get result of moo file after install local msi with list arguments
win_stat:
path: C:\ansible_win_package\moo.exe
register: install_msi_list_arguments_moo
- name: get result of cow file after install local msi with list arguments
win_stat:
path: C:\ansible_win_package\cow.exe
register: install_msi_list_arguments_cow
- name: assert results of install msi to custom path using list arguments
assert:
that:
- install_msi_list_arguments is changed
- install_msi_list_arguments.reboot_required == False
- install_msi_list_arguments.rc == 0
- install_msi_list_arguments_moo.stat.exists == True
- install_msi_list_arguments_cow.stat.exists == False
- name: uninstall good msi after list argument test
win_package:
path: '{{ test_path }}\good.msi'
state: absent
always:
- name: remove spaceless folder for argument list test
win_file:
path: C:\ansible_win_package
state: absent