Support lists of packages in win_winget module

This commit is contained in:
Kenneth Benzie 2024-12-10 23:19:12 +00:00
parent a9aa1bdaaf
commit 1995bf3bc2
2 changed files with 37 additions and 34 deletions

View File

@ -6,8 +6,9 @@
$module = [Ansible.Basic.AnsibleModule]::Create($args, @{ $module = [Ansible.Basic.AnsibleModule]::Create($args, @{
options = @{ options = @{
name = @{ name = @{
type = "str" type = "list"
default = $null elements = "str"
required = $true
} }
state = @{ state = @{
type = "str" type = "str"
@ -18,7 +19,7 @@ $module = [Ansible.Basic.AnsibleModule]::Create($args, @{
supports_check_mode = $false supports_check_mode = $false
}) })
$name = $module.Params.name $names = $module.Params.name
$state = $module.Params.state $state = $module.Params.state
$winget = Get-ExecutablePath "winget" $winget = Get-ExecutablePath "winget"
$noPackageString = "No installed package found matching input criteria." $noPackageString = "No installed package found matching input criteria."
@ -48,7 +49,8 @@ function Test-UpgradeAvailable {
return $true return $true
} }
switch ($state) { foreach ($name in $names) {
switch ($state) {
"absent" { "absent" {
if (Test-Installed) { if (Test-Installed) {
$command = "`"$winget`" uninstall `"$name`"" $command = "`"$winget`" uninstall `"$name`""
@ -90,6 +92,7 @@ switch ($state) {
$module.Result.changed = $true $module.Result.changed = $true
} }
} }
}
} }
$module.Result.rc = 0 $module.Result.rc = 0

View File

@ -11,7 +11,7 @@ options:
name: name:
description: description:
- Name of the package to manage. - Name of the package to manage.
type: str type: list[str]
state: state:
description: description:
- Indicates the desired package state. V(latest) ensures that the latest - Indicates the desired package state. V(latest) ensures that the latest