与厨师一起安装多个包

时间:2016-07-12 09:44:34

标签: package chef redhat

当我尝试使用通配符命名安装多个包时,出现以下错误:

 * 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*]'
    ============================================================================                                                                                        ====

食谱代码是:

package 'mysql-server' do
  action :install
end

package 'mysql*' do
  action :install
end

2 个答案:

答案 0 :(得分:16)

您必须使用确切的包名称。主厨package资源无法找到匹配的包。

资源的名称(包裹之后的部分)用作包名称并提供给底层系统(RH上的yum系统,类似debian的系统)

如果你有多个要安装的软件包和一个通用配置,你可以在你的配方中循环它们:

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

使用一些ruby语法可以简化数组创建,如构建器%w

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

由于主厨12.1 package资源直接接受array of packages,所以:

package %w(mysql-server mysql-common mysql-client)

答案 1 :(得分:-1)

这可以使用厨师案例解决。请看下面的

将以下内容添加到您的属性文件中:

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

然后,将以下内容添加到配方文件(recipes / default.rb):

node[:cookbookname][:packages].each do |pkg|
  package pkg do
    action :install
    retries 3
    retry_delay 5
  end
end