|
|
|
@ -19,13 +19,13 @@
|
|
|
|
|
# WANT_JSON
|
|
|
|
|
# POWERSHELL_COMMON
|
|
|
|
|
|
|
|
|
|
# TODO: Add check-mode support
|
|
|
|
|
|
|
|
|
|
$params = Parse-Args $args
|
|
|
|
|
$params = Parse-Args $args -supports_check_mode $true
|
|
|
|
|
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
|
|
|
|
|
|
|
|
|
$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"
|
|
|
|
|
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "present" -validateset "absent","present"
|
|
|
|
|
$creates = Get-AnsibleParam -obj $params -name "creates" -type "path"
|
|
|
|
|
$removes = Get-AnsibleParam -obj $params -name "removes" -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
|
|
|
|
|
|
|
|
|
@ -33,35 +33,31 @@ $result = @{
|
|
|
|
|
changed = $false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (($creates -ne $null) -and ($state -ne "absent") -and (Test-Path $creates)) {
|
|
|
|
|
Exit-Json $result
|
|
|
|
|
if (-not (Test-Path -Path $path)) {
|
|
|
|
|
Fail-Json $result "The MSI file ($path) was not found."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (-not (Test-Path $path)) {
|
|
|
|
|
Fail-Json $result "Cannot find $path."
|
|
|
|
|
if ($creates -and (Test-Path -Path $creates)) {
|
|
|
|
|
Exit-Json $result "The 'creates' file or directory ($creates) already exists."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
}
|
|
|
|
|
if ($removes -and -not (Test-Path -Path $removes)) {
|
|
|
|
|
Exit-Json $result "The 'removes' file or directory ($removes) does not exist."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
if (-not $check_mode) {
|
|
|
|
|
|
|
|
|
|
if ($wait) {
|
|
|
|
|
Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /l $logfile $extra_args" -Verb Runas -Wait
|
|
|
|
|
$logfile = [IO.Path]::GetTempFileName()
|
|
|
|
|
if ($state -eq "absent") {
|
|
|
|
|
Start-Process -FilePath msiexec.exe -ArgumentList "/x `"$path`" /qn /log $logfile $extra_args" -Verb Runas -Wait:$wait
|
|
|
|
|
} else {
|
|
|
|
|
Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /l $logfile $extra_args" -Verb Runas
|
|
|
|
|
Start-Process -FilePath msiexec.exe -ArgumentList "/i `"$path`" /qn /log $logfile $extra_args" -Verb Runas -Wait:$wait
|
|
|
|
|
}
|
|
|
|
|
$result.log = Get-Content $logfile | Out-String
|
|
|
|
|
Remove-Item $logfile
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result.changed = $true
|
|
|
|
|
$result.log = Get-Content $logfile | Out-String
|
|
|
|
|
Remove-Item $logfile
|
|
|
|
|
|
|
|
|
|
Exit-Json $result
|