From f731e68bca33b1a80736ee759d36d9d20c80561a Mon Sep 17 00:00:00 2001 From: Simon Liddicott Date: Mon, 8 Oct 2018 07:28:28 +0100 Subject: [PATCH] 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 --- changelogs/fragments/win_package_chdir.yaml | 2 ++ lib/ansible/modules/windows/win_package.ps1 | 27 +++++++++++++++------ lib/ansible/modules/windows/win_package.py | 6 +++++ 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/win_package_chdir.yaml diff --git a/changelogs/fragments/win_package_chdir.yaml b/changelogs/fragments/win_package_chdir.yaml new file mode 100644 index 00000000000..ff8779266e6 --- /dev/null +++ b/changelogs/fragments/win_package_chdir.yaml @@ -0,0 +1,2 @@ +minor_changes: +- win_package - added the ``chdir`` option to specify the working directory used when installing and uninstalling a package. diff --git a/lib/ansible/modules/windows/win_package.ps1 b/lib/ansible/modules/windows/win_package.ps1 index d1aec278e25..bc8f54c512a 100644 --- a/lib/ansible/modules/windows/win_package.ps1 +++ b/lib/ansible/modules/windows/win_package.ps1 @@ -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)) { diff --git a/lib/ansible/modules/windows/win_package.py b/lib/ansible/modules/windows/win_package.py index bff12214898..0ac4a088967 100644 --- a/lib/ansible/modules/windows/win_package.py +++ b/lib/ansible/modules/windows/win_package.py @@ -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