From ba02d9b85ca8b1128f1f38d0746983cce7241700 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Sat, 28 Jan 2017 00:11:09 +0100 Subject: [PATCH] Add -type "path" to path and creates parameter (#20402) I intended to update the documentation, but it appears the website docs are behind the actual documentation (as the website doesn't show the default values for booleans). So I ended up adding the missing -type "path" and use the default $null value for undefined parameters. --- lib/ansible/modules/windows/win_msi.ps1 | 71 +++++++++++-------------- lib/ansible/modules/windows/win_msi.py | 4 +- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/lib/ansible/modules/windows/win_msi.ps1 b/lib/ansible/modules/windows/win_msi.ps1 index 3af765a705..07126583d1 100644 --- a/lib/ansible/modules/windows/win_msi.ps1 +++ b/lib/ansible/modules/windows/win_msi.ps1 @@ -19,52 +19,45 @@ # WANT_JSON # POWERSHELL_COMMON -$params = Parse-Args $args; +# TODO: Add check-mode support -$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" "" -$wait = Get-Attr $params "wait" $false | ConvertTo-Bool +$params = Parse-Args $args -$result = New-Object psobject @{ +$path = Get-AnsibleParam -obj $params -name "path" -type "path" -failifempty $true +$state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "present" -validateset "present","absent" +$creates = Get-AnsibleParam -obj $params -name "creates" -type "path" +$extra_args = Get-AnsibleParam -obj $params -name "extra_args" -type "str" -default "" +$wait = Get-AnsibleParam -obj $params -name "wait" -type "bool" -default $false + +$result = @{ changed = $false -}; - -If (($creates -ne $false) -and ($state -ne "absent") -and (Test-Path $creates)) -{ - Exit-Json $result; } -$logfile = [IO.Path]::GetTempFileName(); -if ($state -eq "absent") -{ - If ($wait) - { - Start-Process -FilePath msiexec.exe -ArgumentList "/x `"$path`" /qn /l $logfile $extra_args" -Verb Runas -Wait; - } - Else - { - Start-Process -FilePath msiexec.exe -ArgumentList "/x `"$path`" /qn /l $logfile $extra_args" -Verb Runas; - } -} -Else -{ - If ($wait) - { - Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /l $logfile $extra_args" -Verb Runas -Wait; - } - Else - { - Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /l $logfile $extra_args" -Verb Runas; - } +if (($creates -ne $null) -and ($state -ne "absent") -and (Test-Path $creates)) { + Exit-Json $result } -Set-Attr $result "changed" $true; +$logfile = [IO.Path]::GetTempFileName() +if ($state -eq "absent") { -$logcontents = Get-Content $logfile | Out-String; -Remove-Item $logfile; + if ($wait) { + Start-Process -FilePath msiexec.exe -ArgumentList "/x `"$path`" /qn /l $logfile $extra_args" -Verb Runas -Wait + } else { + Start-Process -FilePath msiexec.exe -ArgumentList "/x `"$path`" /qn /l $logfile $extra_args" -Verb Runas + } -Set-Attr $result "log" $logcontents; +} else { -Exit-Json $result; \ No newline at end of file + if ($wait) { + Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /l $logfile $extra_args" -Verb Runas -Wait + } else { + Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /l $logfile $extra_args" -Verb Runas + } + +} + +$result.changed = $true +$result.log = Get-Content $logfile | Out-String +Remove-Item $logfile + +Exit-Json $result \ No newline at end of file diff --git a/lib/ansible/modules/windows/win_msi.py b/lib/ansible/modules/windows/win_msi.py index 7aa548967f..0a306608fd 100644 --- a/lib/ansible/modules/windows/win_msi.py +++ b/lib/ansible/modules/windows/win_msi.py @@ -41,7 +41,6 @@ options: extra_args: description: - Additional arguments to pass to the msiexec.exe command - required: false state: description: - Whether the MSI file should be installed or uninstalled @@ -61,6 +60,9 @@ options: - true - false default: false +notes: +- Check-mode support is currently not supported. +- Please look into M(win_package) instead, this package will be deprecated in Ansible v2.3. author: "Matt Martz (@sivel)" '''