Installing cartoon packs with a chef

When I try to install multiple packages with a wildcard name, I received 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:

 package 'mysql-server' do action :install end package 'mysql*' do action :install end 
+5
source share
2 answers

You must use the exact package name. The chef package resource is not magic to find matching packages.

The resource name (the part immediately after the package) is used as the package name and is assigned to the base system (yum on RH-like systems suitable for such systems)

If you have several packages to install and a general configuration, you can iterate over them in your recipe:

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

Creating an array can be simplified with some ruby ​​syntax like the words builder %w :

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

Since chef 12.1, the package resource accepts an array of packages as follows:

 package %w(mysql-server mysql-common mysql-client) 
+13
source

This can be solved with covers. See below

add the following to the attribute 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 
-1
source

All Articles