mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-27 15:11:23 -07: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:
parent
a657572240
commit
ba02d9b85c
2 changed files with 35 additions and 40 deletions
|
@ -19,52 +19,45 @@
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
# POWERSHELL_COMMON
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
# TODO: Add check-mode support
|
||||||
|
|
||||||
$path = Get-Attr $params "path" -failifempty $true
|
$params = Parse-Args $args
|
||||||
$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
|
|
||||||
|
|
||||||
$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
|
changed = $false
|
||||||
};
|
|
||||||
|
|
||||||
If (($creates -ne $false) -and ($state -ne "absent") -and (Test-Path $creates))
|
|
||||||
{
|
|
||||||
Exit-Json $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$logfile = [IO.Path]::GetTempFileName();
|
if (($creates -ne $null) -and ($state -ne "absent") -and (Test-Path $creates)) {
|
||||||
if ($state -eq "absent")
|
Exit-Json $result
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Attr $result "changed" $true;
|
$logfile = [IO.Path]::GetTempFileName()
|
||||||
|
if ($state -eq "absent") {
|
||||||
|
|
||||||
$logcontents = Get-Content $logfile | Out-String;
|
if ($wait) {
|
||||||
Remove-Item $logfile;
|
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
|
|
@ -41,7 +41,6 @@ options:
|
||||||
extra_args:
|
extra_args:
|
||||||
description:
|
description:
|
||||||
- Additional arguments to pass to the msiexec.exe command
|
- Additional arguments to pass to the msiexec.exe command
|
||||||
required: false
|
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Whether the MSI file should be installed or uninstalled
|
- Whether the MSI file should be installed or uninstalled
|
||||||
|
@ -61,6 +60,9 @@ options:
|
||||||
- true
|
- true
|
||||||
- false
|
- false
|
||||||
default: 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)"
|
author: "Matt Martz (@sivel)"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue