Added support for user-specified log file in win_package (#51104)
* Added support for user-specified log file in win_package - feature (#38353) * added integration tests for win_package log_path support feature (#38353), and applied review feedback * win_package log_path support feature (#38353) - fixed typo in win-package.py documentation * win_package log_path support feature (#38353) - improved an integration test and better doc in win-package.py
This commit is contained in:
parent
467d2ebecd
commit
d4a07f9573
4 changed files with 47 additions and 10 deletions
|
@ -25,6 +25,7 @@ $validate_certs = Get-AnsibleParam -obj $params -name "validate_certs" -type "bo
|
|||
$creates_path = Get-AnsibleParam -obj $params -name "creates_path" -type "path"
|
||||
$creates_version = Get-AnsibleParam -obj $params -name "creates_version" -type "str"
|
||||
$creates_service = Get-AnsibleParam -obj $params -name "creates_service" -type "str"
|
||||
$log_path = Get-AnsibleParam -obj $params -name "log_path" -type "path"
|
||||
|
||||
$result = @{
|
||||
changed = $false
|
||||
|
@ -326,10 +327,12 @@ if ($state -eq "absent") {
|
|||
|
||||
if ($program_metadata.msi -eq $true) {
|
||||
# we are uninstalling an msi
|
||||
$temp_path = [System.IO.Path]::GetTempPath()
|
||||
$log_file = [System.IO.Path]::GetRandomFileName()
|
||||
$log_path = Join-Path -Path $temp_path -ChildPath $log_file
|
||||
$cleanup_artifacts += $log_path
|
||||
if ( -Not $log_path ) {
|
||||
$temp_path = [System.IO.Path]::GetTempPath()
|
||||
$log_file = [System.IO.Path]::GetRandomFileName()
|
||||
$log_path = Join-Path -Path $temp_path -ChildPath $log_file
|
||||
$cleanup_artifacts += $log_path
|
||||
}
|
||||
|
||||
if ($program_metadata.product_id -ne $null) {
|
||||
$id = $program_metadata.product_id
|
||||
|
@ -418,11 +421,13 @@ if ($state -eq "absent") {
|
|||
|
||||
if ($program_metadata.msi -eq $true) {
|
||||
# we are installing an msi
|
||||
$temp_path = [System.IO.Path]::GetTempPath()
|
||||
$log_file = [System.IO.Path]::GetRandomFileName()
|
||||
$log_path = Join-Path -Path $temp_path -ChildPath $log_file
|
||||
if ( -Not $log_path ) {
|
||||
$temp_path = [System.IO.Path]::GetTempPath()
|
||||
$log_file = [System.IO.Path]::GetRandomFileName()
|
||||
$log_path = Join-Path -Path $temp_path -ChildPath $log_file
|
||||
$cleanup_artifacts += $log_path
|
||||
}
|
||||
|
||||
$cleanup_artifacts += $log_path
|
||||
$install_arguments = @("$env:windir\system32\msiexec.exe", "/i", $local_path, "/L*V", $log_path, "/qn", "/norestart")
|
||||
} else {
|
||||
$log_path = $null
|
||||
|
|
|
@ -130,6 +130,13 @@ options:
|
|||
type: bool
|
||||
default: yes
|
||||
version_added: '2.4'
|
||||
log_path:
|
||||
description:
|
||||
- Specifies the path to a log file that is persisted after an MSI package is installed or uninstalled.
|
||||
- When omitted, a temporary log file is used for MSI packages.
|
||||
- This is only valid for MSI files, use C(arguments) for other package types.
|
||||
type: path
|
||||
version_added: '2.8'
|
||||
notes:
|
||||
- When C(state=absent) and the product is an exe, the path may be different
|
||||
from what was used to install the package originally. If path is not set then
|
||||
|
@ -163,7 +170,7 @@ EXAMPLES = r'''
|
|||
product_id: '{CF2BEA3C-26EA-32F8-AA9B-331F7E34BA97}'
|
||||
arguments: /install /passive /norestart
|
||||
|
||||
- name: Install Visual C thingy with list of arguments instead of a string
|
||||
- name: Install Visual C thingy with list of arguments instead of a string, and permanent log
|
||||
win_package:
|
||||
path: http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe
|
||||
product_id: '{CF2BEA3C-26EA-32F8-AA9B-331F7E34BA97}'
|
||||
|
@ -171,6 +178,7 @@ EXAMPLES = r'''
|
|||
- /install
|
||||
- /passive
|
||||
- /norestart
|
||||
log_path: D:\logs\vcredist_x64-exe-{{lookup('pipe', 'date +%Y%m%dT%H%M%S')}}.log
|
||||
|
||||
- name: Install Remote Desktop Connection Manager from msi
|
||||
win_package:
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
# spaces are tricky, let's have one by default
|
||||
test_win_package_path_safe: C:\ansible\win_package
|
||||
test_win_package_path: C:\ansible\win package
|
||||
test_win_package_log_path_install: C:\ansible\win package\test-install.log
|
||||
test_win_package_log_path_uninstall: C:\ansible\win package\test-uninstall.log
|
||||
test_win_package_good_url: https://s3.amazonaws.com/ansible-ci-files/test/integration/roles/test_win_package/good.msi
|
||||
test_win_package_reboot_url: https://s3.amazonaws.com/ansible-ci-files/test/integration/roles/test_win_package/reboot.msi
|
||||
test_win_package_bad_url: https://s3.amazonaws.com/ansible-ci-files/test/integration/roles/test_win_package/bad.msi
|
||||
|
|
|
@ -25,10 +25,11 @@
|
|||
- install_local_msi_check.reboot_required == False
|
||||
- install_local_msi_actual_check.exists == False
|
||||
|
||||
- name: install local msi
|
||||
- name: install local msi with log
|
||||
win_package:
|
||||
path: '{{test_win_package_path}}\good.msi'
|
||||
state: present
|
||||
log_path: "{{test_win_package_log_path_install}}"
|
||||
register: install_local_msi
|
||||
|
||||
- name: get result of install local msi
|
||||
|
@ -44,6 +45,16 @@
|
|||
- install_local_msi.rc == 0
|
||||
- install_local_msi_actual.exists == True
|
||||
|
||||
- name: get result of install local msi log_path
|
||||
win_stat:
|
||||
path: "{{test_win_package_log_path_install}}"
|
||||
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_win_package_path}}\good.msi'
|
||||
|
@ -78,6 +89,7 @@
|
|||
win_package:
|
||||
path: '{{test_win_package_path}}\good.msi'
|
||||
state: absent
|
||||
log_path: "{{test_win_package_log_path_uninstall}}"
|
||||
register: uninstall_path_local_msi
|
||||
|
||||
- name: get result of uninstall local msi with path
|
||||
|
@ -93,6 +105,16 @@
|
|||
- 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_win_package_log_path_uninstall}}"
|
||||
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_win_package_path}}\good.msi'
|
||||
|
|
Loading…
Reference in a new issue