mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-19 15:21:27 +00:00
win_chocolatey: Fix state=latest when absent (#23041)
When using state=latest with the package not being installled, Ansible complains that the package is not installed and fails the task. Whereas the expected behaviour is to install the package when it is missing. This PR fixes this behaviour.
This commit is contained in:
@@ -247,7 +247,7 @@ Function Choco-Install
|
||||
[int]$timeout
|
||||
)
|
||||
|
||||
if ((Choco-IsInstalled $package) -and -not $force)
|
||||
if (Choco-IsInstalled $package)
|
||||
{
|
||||
if ($upgrade)
|
||||
{
|
||||
@@ -258,8 +258,7 @@ Function Choco-Install
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (-not $force)
|
||||
elseif (-not $force)
|
||||
{
|
||||
return
|
||||
}
|
||||
@@ -385,20 +384,13 @@ Try
|
||||
{
|
||||
Chocolatey-Install-Upgrade
|
||||
|
||||
if ($state -eq "present")
|
||||
if ($state -eq "present" -or $state -eq "latest")
|
||||
{
|
||||
Choco-Install -package $package -version $version -source $source -force $force `
|
||||
-installargs $installargs -packageparams $packageparams `
|
||||
-allowemptychecksums $allowemptychecksums -ignorechecksums $ignorechecksums `
|
||||
-ignoredependencies $ignoredependencies -timeout $timeout
|
||||
}
|
||||
elseif ($state -eq "latest")
|
||||
{
|
||||
Choco-Upgrade -package $package -version $version -source $source -force $force `
|
||||
-installargs $installargs -packageparams $packageparams `
|
||||
-allowemptychecksums $allowemptychecksums -ignorechecksums $ignorechecksums `
|
||||
-ignoredependencies $ignoredependencies -timeout $timeout
|
||||
}
|
||||
elseif ($state -eq "absent")
|
||||
{
|
||||
Choco-Uninstall -package $package -version $version -force $force -timeout $timeout
|
||||
|
||||
Reference in New Issue
Block a user