【问题标题】:Why chef does not execute recipe line by line?为什么厨师不逐行执行食谱?
【发布时间】:2016-01-29 04:53:13
【问题描述】:

问题是厨师尝试先安装模板,然后才安装包。如果我评论模板块,厨师将安装 sphinxsearch 包。

但是如果模板块没有被注释,sphinxsearch包没有安装,厨师失败并报错

资源模板[/etc/sphinxsearch/sphinx.conf]配置为通知资源service[sphinxsearch]动作重载,但是资源集合中找不到service[sphinxsearch]`

为什么会这样?

##
# Install system packages
##
node['website']['packages'].each do |pkg|
    log 'Installing ' + pkg
    package pkg
end

##
# Configure sphinx
##
template "/etc/sphinxsearch/sphinx.conf" do
    source 'sphinx.erb'
    owner 'root'
    group 'root'
    mode 00644
    notifies :reload, 'service[sphinxsearch]', :delayed
end

【问题讨论】:

  • 您是否尝试在运行列表之前添加定义service[sphinxsearch] 的说明书?如有疑问,请添加includes_recipe sphinxsearch(或食谱名称)。
  • @StephenKing 不,我刚刚使用package "sphinxsearch" 安装包。还不够吗?
  • @avasin 您要求厨师通知名为 sphinxsearch 的 service 资源,但您的食谱中没有 service 资源。我强烈建议您阅读 learn.chef.io 以了解厨师的基础知识

标签: ruby chef-infra


【解决方案1】:

chef 中的notifiessubscribes 都在尝试访问已在您的 chef 运行中定义的资源。然后,他们将对这些资源采取指示行动。在你的情况下:

notifies :reload, 'service[sphinxsearch]', :delayed

正在寻找名为sphinxsearchservice 类型的资源并对其调用reload 操作。如果在资源收集(编译)阶段结束时,chef 找不到service[sphinxsearch] 资源,那么它会抛出错误。您看不到安装的软件包,因为 chef 从未进入执行阶段。 (有关厨师的两阶段性质的更多信息,请参阅this answer

正如@IsabelHM 所指出的,您可以通过添加来解决问题

service 'sphinxsearch' do
  action [:enable, :start]
end

我建议您使用[:enable, :start] 而不是:nothing,因为这将确保服务始终运行,即使您的模板没有更改。另外,请注意service 资源确实为您添加服务配置。因此,如果 sphinxsearch 包没有添加服务配置,您还需要 cookbook_filetemplateremote_file 资源来创建服务配置。

【讨论】:

  • 非常感谢您如此详细的回复。
  • 优秀,有用的答案
【解决方案2】:

将此添加到您的食谱中。

service 'sphinxsearch' do
  action :nothing
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-16
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多