community.general/lib/ansible/modules/windows/win_msi.ps1
Dag Wieers ba02d9b85c 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.
2017-01-27 15:11:09 -08:00

63 lines
No EOL
2.1 KiB
PowerShell

#!powershell
# (c) 2014, Matt Martz <matt@sivel.net>, and others
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# WANT_JSON
# POWERSHELL_COMMON
# TODO: Add check-mode support
$params = Parse-Args $args
$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 $null) -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
}
}
$result.changed = $true
$result.log = Get-Content $logfile | Out-String
Remove-Item $logfile
Exit-Json $result