Installing multiples packages with chef

11,042

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)
Share:
11,042
Admin
Author by

Admin

Updated on July 25, 2022

Comments

  • Admin
    Admin over 1 year

    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
    
  • Tensibai
    Tensibai about 6 years
    The package resource accept an array of packages for a while now, there's no reason to loop over it anymore.