diff --git a/library/win_winget.ps1 b/library/win_winget.ps1 index 1915df3..2520a6a 100644 --- a/library/win_winget.ps1 +++ b/library/win_winget.ps1 @@ -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 } } } diff --git a/library/win_winget.py b/library/win_winget.py index 992960f..8226601 100644 --- a/library/win_winget.py +++ b/library/win_winget.py @@ -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