1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/lib/ansible/modules/windows/_win_msi.ps1
Dag Wieers 95a1170908 Windows: Add "special" parameter types to docs (#42853)
* Windows: Add special parameter types

Adding explicit parameter types now exposes this information in the
module documentation, and proves really helpful.

We only do this for non-string types as strings, mostly because strings
are implicit.

PS We also make copyright statements consistent and use #Requires for
explicit library imports

* Type "string" must be type "str"

* A few more Copyright corrections

* More fixes

* Don't add file encoding to Powershell files

* Don't add missing interfacetypes parameter

Otherwise CI demands an incorrect version_added

* Small fix
2018-07-17 14:29:05 -07:00

49 lines
1.7 KiB
PowerShell

#!powershell
# Copyright: (c) 2014, Matt Martz <matt@sivel.net>, and others
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#Requires -Module Ansible.ModuleUtils.Legacy
$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 "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
$result = @{
changed = $false
}
if (-not (Test-Path -Path $path)) {
Fail-Json $result "The MSI file ($path) was not found."
}
if ($creates -and (Test-Path -Path $creates)) {
Exit-Json $result "The 'creates' file or directory ($creates) already exists."
}
if ($removes -and -not (Test-Path -Path $removes)) {
Exit-Json $result "The 'removes' file or directory ($removes) does not exist."
}
if (-not $check_mode) {
$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 /log $logfile $extra_args" -Verb Runas -Wait:$wait
}
$result.log = Get-Content $logfile | Out-String
Remove-Item $logfile
}
$result.changed = $true
Exit-Json $result