Jason Capriotti
Jason Capriotti

Reputation: 2060

Chef + Chocolatey - "No candidate version available for (package)"

We've been using Chef and Chocolatey separately for a while and recently started using them together to easily install some Windows packages.

For example:

include_recipe 'chocolatey::default'

chocolatey_package 'git.install' do
  action :install
end

chocolatey_package 'nuget.commandline' do
  action :install
end

chocolatey_package 'docker-compose' do
  action :install
  version '1.21.2'
end

chocolatey_package 'gitlab-runner' do
  action :install
  version '11.0.0'
end

That recipe has worked, but now we've been getting these errors without any other changes:

* chocolatey_package[git.install] action install
  - install version 2.18.0 of package git.install
* chocolatey_package[nuget.commandline] action install
  - install version 4.8.1 of package nuget.commandline
* chocolatey_package[docker-compose] action install
  - install version 1.21.2 of package docker-compose
* chocolatey_package[gitlab-runner] action install
  * No candidate version available for gitlab-runner
  ================================================================================
  Error executing action `install` on resource 'chocolatey_package[gitlab-runner]'
  ================================================================================

  Chef::Exceptions::Package
  -------------------------
  No candidate version available for gitlab-runner

Note the successful installs, followed by a failure.

That initially happened for the git package, and out of frustration, I changed it to git.install, which worked. But now it just started happening with gitlab-runner.

Has anyone seen this type of failure where it works one day and not the next? I've verified the package exists and I can manually pull it down with choco install.

My next troubleshooting step might be to dig into that resource; I know that error message can happen with package installs on Linux platforms, so maybe the error description is misleading... i.e. chocolatey_package is either throwing the exception or the handler is doing too general of a catch (to use .NET terms).

Upvotes: 1

Views: 2147

Answers (2)

stanhu
stanhu

Reputation: 136

For those of you running into this problem today, try to update Chef. This problem might be due to a choco.exe v1 vs v2 issue. v2 now requires using search -r instead of list -r to find uninstalled packages:

PS C:\> choco --version
2.2.2
PS C:\> choco search -r visualstudio2019buildtools
visualstudio2019buildtools|16.11.29
PS C:\> choco list -r visualstudio2019buildtools
visualstudio-installer|2.0.3

https://github.com/chef/chef/pull/13833 fixed this in Chef v18.2.41.

https://github.com/chef/chef/pull/13928 backported this to Chef v17.10.82.

Note that unless choco.exe is in the PATH, you might run into a regression with the choco --version check that will be fixed with https://github.com/chef/chef/pull/13935.

Upvotes: 0

Brandon Hawbaker
Brandon Hawbaker

Reputation: 338

This is one of the most annoying issues I've ever faced. Chocolatey.org is very unreliable, indeed. However, I can directly install on the command-line immediately following this error, but through the chocolatey_package chef resource, it fails with the dreaded "No candidate version available" pretty much every time, regardless of the state of chocolatey.org. Hopefully, Chef eventually get their act together. In the meantime, here's a workaround that has worked for me for quite some time.

choco source add -n=local -s"[PATH]" -u=[USERNAME] -p=[PASSWORD]

Then go to chocolatey.org, find your package, download it to that location, and then rerun your recipe. This works very well, because you no longer depend on external resources nearly as much and it's faster, but keep in mind that when new packages are released, you'll more than likely need to refresh with the latest packages.

Upvotes: 0

Related Questions