mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add chdir support to win_package (#46123)
* Add chdir support to win_package * Add chdir support to uninstall too. * Update docs to account for uninstall. * Correct variable substitution for hashtable. * added changelog fragment
This commit is contained in:
parent
bc6d441cf2
commit
f731e68bca
3 changed files with 27 additions and 8 deletions
2
changelogs/fragments/win_package_chdir.yaml
Normal file
2
changelogs/fragments/win_package_chdir.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- win_package - added the ``chdir`` option to specify the working directory used when installing and uninstalling a package.
|
|
@ -16,6 +16,7 @@ $check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "b
|
|||
$arguments = Get-AnsibleParam -obj $params -name "arguments"
|
||||
$expected_return_code = Get-AnsibleParam -obj $params -name "expected_return_code" -type "list" -default @(0, 3010)
|
||||
$path = Get-AnsibleParam -obj $params -name "path" -type "str"
|
||||
$chdir = Get-AnsibleParam -obj $params -name "chdir" -type "path"
|
||||
$product_id = Get-AnsibleParam -obj $params -name "product_id" -type "str" -aliases "productid"
|
||||
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "present" -validateset "absent","present" -aliases "ensure"
|
||||
$username = Get-AnsibleParam -obj $params -name "username" -type "str" -aliases "user_name"
|
||||
|
@ -343,15 +344,20 @@ if ($state -eq "absent") {
|
|||
}
|
||||
|
||||
if (-not $check_mode) {
|
||||
$uninstall_command = Argv-ToString -arguments $uninstall_arguments
|
||||
$command_args = @{
|
||||
command = Argv-ToString -arguments $uninstall_arguments
|
||||
}
|
||||
if ($arguments -ne $null) {
|
||||
$uninstall_command += " $arguments"
|
||||
$command_args['command'] += " $arguments"
|
||||
}
|
||||
if ($chdir) {
|
||||
$command_args['working_directory'] = $chdir
|
||||
}
|
||||
|
||||
try {
|
||||
$process_result = Run-Command -command $uninstall_command
|
||||
$process_result = Run-Command @command_args
|
||||
} catch {
|
||||
Fail-Json -obj $result -message "failed to run uninstall process ($uninstall_command): $($_.Exception.Message)"
|
||||
Fail-Json -obj $result -message "failed to run uninstall process ($($command_args['command'])): $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
if (($log_path -ne $null) -and (Test-Path -Path $log_path)) {
|
||||
|
@ -424,15 +430,20 @@ if ($state -eq "absent") {
|
|||
}
|
||||
|
||||
if (-not $check_mode) {
|
||||
$install_command = Argv-ToString -arguments $install_arguments
|
||||
$command_args = @{
|
||||
command = Argv-ToString -arguments $install_arguments
|
||||
}
|
||||
if ($arguments -ne $null) {
|
||||
$install_command += " $arguments"
|
||||
$command_args['command'] += " $arguments"
|
||||
}
|
||||
if ($chdir) {
|
||||
$command_args['working_directory'] = $chdir
|
||||
}
|
||||
|
||||
try {
|
||||
$process_result = Run-Command -command $install_command
|
||||
$process_result = Run-Command @command_args
|
||||
} catch {
|
||||
Fail-Json -obj $result -message "failed to run install process ($install_command): $($_.Exception.Message)"
|
||||
Fail-Json -obj $result -message "failed to run install process ($($command_args['command'])): $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
if (($log_path -ne $null) -and (Test-Path -Path $log_path)) {
|
||||
|
|
|
@ -32,6 +32,12 @@ options:
|
|||
module will escape the arguments as necessary, it is recommended to use a
|
||||
string when dealing with MSI packages due to the unique escaping issues
|
||||
with msiexec.
|
||||
chdir:
|
||||
description:
|
||||
- Set the specified path as the current working directory before installing
|
||||
or uninstalling a package.
|
||||
type: path
|
||||
version_added: '2.8'
|
||||
creates_path:
|
||||
description:
|
||||
- Will check the existance of the path specified and use the result to
|
||||
|
|
Loading…
Reference in a new issue