9

When I try to install multiples packages with a wildcard naming I got the following error:

 * yum_package[mysql-server] action install (up to date)
 * yum_package[mysql*] action install
 * No candidate version available for mysql*
    ============================================================================                                                                                        ====
    Error executing action `install` on resource 'yum_package[mysql*]'
    ============================================================================                                                                                        ====

Recipe code is:

package 'mysql-server' do
  action :install
end

package 'mysql*' do
  action :install
end
chicks
  • 2,393
  • 3
  • 24
  • 40
systemadmin
  • 91
  • 1
  • 1
  • 2

2 Answers2

20

You have to use the exact package name. The chef package resource does no magic to find matching packages.

The name of the resource (the part just after package) is used as the package name and given to the underlying system (yum on RH like systems, apt on debian like systems)

If you have multiples packages to install and a common configuration you can loop over them in your recipe instead:

['mysql-server','mysql-common','mysql-client'].each do |p|
  package p do
    action :install
  end
end

The array creation could be simplified with some ruby syntax as the words builder %w:

%w(mysql-server mysql-common mysql-client).each [...]

Since chef 12.1 the package resource accept an array of packages directly like this:

package %w(mysql-server mysql-common mysql-client)
Tensibai
  • 15,557
  • 1
  • 37
  • 57
-1

This can be resolved using chef cases. Please see below

add the following to your attributes file:

packages = []

case node[:platform_family]
when 'rhel' #based on your OS
  packages = [
    "package1",
    "package2",
    "package3",
    "package4",
    "package5",
    "package6",
    "package7" ## Last line without comma
  ]
end

default[:cookbookname][:packages] = packages

Then, add the following to your recipe file (recipes/default.rb):

node[:cookbookname][:packages].each do |pkg|
  package pkg do
    action :install
    retries 3
    retry_delay 5
  end
end
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
  • The package resource accept an array of packages for a while now, there's no reason to loop over it anymore. – Tensibai Dec 13 '17 at 13:43