From 5ff4d219e0de670c0470f353b05be0ff0a7a9863 Mon Sep 17 00:00:00 2001 From: schwartzmx Date: Tue, 7 Apr 2015 21:28:47 -0500 Subject: [PATCH] updates win_msi to allow install to wait - adds additional wait param - updates to use Start-Process to allow -Wait - this will wait for install/uninstall to complete before continue --- lib/ansible/modules/windows/win_msi.ps1 | 45 +++++++++++++++++++------ lib/ansible/modules/windows/win_msi.py | 15 ++++++++- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/lib/ansible/modules/windows/win_msi.ps1 b/lib/ansible/modules/windows/win_msi.ps1 index f1381e9bf23..7db67546013 100644 --- a/lib/ansible/modules/windows/win_msi.ps1 +++ b/lib/ansible/modules/windows/win_msi.ps1 @@ -21,14 +21,25 @@ $params = Parse-Args $args; -$path = Get-Attr $params "path" -failifempty $true -$state = Get-Attr $params "state" "present" -$creates = Get-Attr $params "creates" $false -$extra_args = Get-Attr $params "extra_args" "" +$result = New-Object psobject; +Set-Attr $result "changed" $false; +$wait = $false -$result = New-Object psobject @{ - changed = $false -}; +If (-not $params.path.GetType) +{ + Fail-Json $result "missing required arguments: path" +} + +If ($params.wait -eq "true" -Or $params.wait -eq "yes") +{ + $wait = $true +} + +$extra_args = "" +If ($params.extra_args.GetType) +{ + $extra_args = $params.extra_args; +} If (($creates -ne $false) -and ($state -ne "absent") -and (Test-Path $creates)) { @@ -36,13 +47,27 @@ If (($creates -ne $false) -and ($state -ne "absent") -and (Test-Path $creates)) } $logfile = [IO.Path]::GetTempFileName(); -if ($state -eq "absent") +If ($params.state.GetType -and $params.state -eq "absent") { - msiexec.exe /x $path /qn /l $logfile $extra_args + If ($wait) + { + Start-Process -FilePath msiexec.exe -ArgumentList "/x $params.path /qb /l $logfile $extra_args" -Verb Runas -Wait; + } + Else + { + Start-Process -FilePath msiexec.exe -ArgumentList "/x $params.path /qb /l $logfile $extra_args" -Verb Runas; + } } Else { - msiexec.exe /i $path /qn /l $logfile $extra_args + If ($wait) + { + Start-Process -FilePath msiexec.exe -ArgumentList "/i $params.path /qb /l $logfile $extra_args" -Verb Runas -Wait; + } + Else + { + Start-Process -FilePath msiexec.exe -ArgumentList "/i $params.path /qb /l $logfile $extra_args" -Verb Runas; + } } Set-Attr $result "changed" $true; diff --git a/lib/ansible/modules/windows/win_msi.py b/lib/ansible/modules/windows/win_msi.py index bd504879a83..9b5861f0053 100644 --- a/lib/ansible/modules/windows/win_msi.py +++ b/lib/ansible/modules/windows/win_msi.py @@ -49,13 +49,26 @@ options: description: - Path to a file created by installing the MSI to prevent from attempting to reinstall the package on every run -author: "Matt Martz (@sivel)" + wait: + version_added: "" + description: + - Specify whether to wait for install or uninstall to complete before continuing. + choices: + - true + - yes + - false + - no + default: false +author: Matt Martz ''' EXAMPLES = ''' # Install an MSI file - win_msi: path=C:\\\\7z920-x64.msi +# Install an MSI, and wait for it to complete before continuing +- win_msi: path=C:\\\\7z920-x64.msi wait=true + # Uninstall an MSI file - win_msi: path=C:\\\\7z920-x64.msi state=absent '''