From d9a6714cb92d1ea97a6d83e1b1066c877a8e8851 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Wed, 29 Mar 2017 02:49:21 +0200 Subject: [PATCH] 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. (cherry picked from commit 521fa9b458c079fc38d6876dff6d6a76599401e5) --- lib/ansible/modules/windows/win_chocolatey.ps1 | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/ansible/modules/windows/win_chocolatey.ps1 b/lib/ansible/modules/windows/win_chocolatey.ps1 index 64ffd417e9b..562beab2df2 100644 --- a/lib/ansible/modules/windows/win_chocolatey.ps1 +++ b/lib/ansible/modules/windows/win_chocolatey.ps1 @@ -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