1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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.
This commit is contained in:
Dag Wieers 2017-01-28 00:11:09 +01:00 committed by Matt Davis
parent a657572240
commit ba02d9b85c
2 changed files with 35 additions and 40 deletions

View file

@ -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;
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

View file

@ -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)"
'''