Support lists of packages in win_winget module
This commit is contained in:
parent
a9aa1bdaaf
commit
1995bf3bc2
@ -6,8 +6,9 @@
|
||||
$module = [Ansible.Basic.AnsibleModule]::Create($args, @{
|
||||
options = @{
|
||||
name = @{
|
||||
type = "str"
|
||||
default = $null
|
||||
type = "list"
|
||||
elements = "str"
|
||||
required = $true
|
||||
}
|
||||
state = @{
|
||||
type = "str"
|
||||
@ -18,7 +19,7 @@ $module = [Ansible.Basic.AnsibleModule]::Create($args, @{
|
||||
supports_check_mode = $false
|
||||
})
|
||||
|
||||
$name = $module.Params.name
|
||||
$names = $module.Params.name
|
||||
$state = $module.Params.state
|
||||
$winget = Get-ExecutablePath "winget"
|
||||
$noPackageString = "No installed package found matching input criteria."
|
||||
@ -48,46 +49,48 @@ function Test-UpgradeAvailable {
|
||||
return $true
|
||||
}
|
||||
|
||||
switch ($state) {
|
||||
"absent" {
|
||||
if (Test-Installed) {
|
||||
$command = "`"$winget`" uninstall `"$name`""
|
||||
$result = Run-Command -command $command
|
||||
if ($result.rc -ne 0) {
|
||||
$module.Result.rc = $result.rc
|
||||
foreach ($name in $names) {
|
||||
switch ($state) {
|
||||
"absent" {
|
||||
if (Test-Installed) {
|
||||
$command = "`"$winget`" uninstall `"$name`""
|
||||
$result = Run-Command -command $command
|
||||
if ($result.rc -ne 0) {
|
||||
$module.Result.rc = $result.rc
|
||||
$module.Result.stdout = $result.stdout
|
||||
$module.FailJson("Failed to uninstall package `"$name`"")
|
||||
}
|
||||
$module.Result.stdout = $result.stdout
|
||||
$module.FailJson("Failed to uninstall package `"$name`"")
|
||||
$module.Result.changed = $true
|
||||
}
|
||||
$module.Result.stdout = $result.stdout
|
||||
$module.Result.changed = $true
|
||||
}
|
||||
}
|
||||
|
||||
"latest" {
|
||||
if (Test-UpgradeAvailable) {
|
||||
$command = "`"$winget`" install `"$name`""
|
||||
$result = Run-Command -command $command
|
||||
if ($result.rc -ne 0) {
|
||||
$module.Result.rc = $result.rc
|
||||
"latest" {
|
||||
if (Test-UpgradeAvailable) {
|
||||
$command = "`"$winget`" install `"$name`""
|
||||
$result = Run-Command -command $command
|
||||
if ($result.rc -ne 0) {
|
||||
$module.Result.rc = $result.rc
|
||||
$module.Result.stdout = $result.stdout
|
||||
$module.FailJson("Failed to install package `"$name`"")
|
||||
}
|
||||
$module.Result.stdout = $result.stdout
|
||||
$module.FailJson("Failed to install package `"$name`"")
|
||||
$module.Result.changed = $true
|
||||
}
|
||||
$module.Result.stdout = $result.stdout
|
||||
$module.Result.changed = $true
|
||||
}
|
||||
}
|
||||
|
||||
"present" {
|
||||
if (!(Test-Installed)) {
|
||||
$command = "`"$winget`" install `"$name`""
|
||||
$result = Run-Command -command $command
|
||||
if ($result.rc -ne 0) {
|
||||
$module.Result.rc = $result.rc
|
||||
"present" {
|
||||
if (!(Test-Installed)) {
|
||||
$command = "`"$winget`" install `"$name`""
|
||||
$result = Run-Command -command $command
|
||||
if ($result.rc -ne 0) {
|
||||
$module.Result.rc = $result.rc
|
||||
$module.Result.stdout = $result.stdout
|
||||
$module.FailJson("Failed to install package `"$name`"")
|
||||
}
|
||||
$module.Result.stdout = $result.stdout
|
||||
$module.FailJson("Failed to install package `"$name`"")
|
||||
$module.Result.changed = $true
|
||||
}
|
||||
$module.Result.stdout = $result.stdout
|
||||
$module.Result.changed = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ options:
|
||||
name:
|
||||
description:
|
||||
- Name of the package to manage.
|
||||
type: str
|
||||
type: list[str]
|
||||
state:
|
||||
description:
|
||||
- Indicates the desired package state. V(latest) ensures that the latest
|
||||
|
Loading…
x
Reference in New Issue
Block a user