Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing multiples packages with chef

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
like image 935
systemadmin Avatar asked Jul 12 '16 09:07

systemadmin


1 Answers

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)
like image 189
Tensibai Avatar answered Sep 23 '22 18:09

Tensibai