【问题标题】:Chef execution order for this recipe此食谱的厨师执行订单
【发布时间】:2018-07-29 13:50:33
【问题描述】:

我有以下厨师食谱。

lazy_message = 'Hello world'
file 'lazy_message' do
  path '/tmp/lazy.txt'
  content "#{lazy_message}"
end 

execute 'yum-makecache' do
  command 'yum makecache'
  notifies :create, 'file[message]', :immediately
  action :nothing
end

package 'bind-utils' do
  action :install
  notifies :run, 'execute[yum-makecache]', :before
end

file 'message' do
  path '/tmp/message.txt'
  content lazy { "#{lazy_message}" }
end

lazy_message = 'Goodbye world'

当我运行它时,它按以下顺序执行。

Synchronizing Cookbooks:
         - lcd_web (0.1.0)
       Installing Cookbook Gems:
       Compiling Cookbooks...
       Converging 4 resources
       Recipe: lcd_web::default
         * file[lazy_message] action create
           - create new file /tmp/lazy.txt
           - update content in file /tmp/lazy.txt from none to 64ec88
           --- /tmp/lazy.txt    2018-07-28 07:47:39.433257401 +0000
           +++ /tmp/.chef-lazy20180728-296-7usgw7.txt   2018-07-28 07:47:39.433257401 +0000
           @@ -1 +1,2 @@
           +Hello world
         * execute[yum-makecache] action nothing (skipped due to action :nothing)
         * yum_package[bind-utils] action install
           - install version 32:9.9.4-61.el7.x86_64 of package bind-utils
         * file[message] action create
           - create new file /tmp/message.txt
           - update content in file /tmp/message.txt from none to b4dabd
           --- /tmp/message.txt 2018-07-28 07:47:52.115780144 +0000
           +++ /tmp/.chef-message20180728-296-tgnjuk.txt    2018-07-28 07:47:52.115780144 +0000
           @@ -1 +1,2 @@
           +Goodbye world
         * execute[yum-makecache] action run
           - execute yum makecache
         * file[message] action create (up to date)

我不明白使用惰性块的执行顺序,: before 和 : immediate 指令。

按照我的说法,执行顺序如下。

  • 执行文件“惰性消息”
  • 转到 yum 'makecache' 但由于无操作而跳过它
  • 转到 bind-utils 但由于 :before 指令而再次跳转到执行 'yum-makecache' 并运行它。

  • 由于 :immediatelyn in 'yum-makecache' 运行文件 'message'

  • 现在运行 bind-utils
  • 再次运行文件“消息”。

但实际输出并不像'bind-utils'在'yum-makecache'之前运行

【问题讨论】:

    标签: chef-infra chef-recipe chef-solo


    【解决方案1】:

    before 通知非常挑剔,基本上只用于在无法升级正在运行的服务的平台上更新包/文件之前停止服务。在时间之前挂起进一步的通知肯定会做不合逻辑的事情,我们不测试也不关心它的行为,因为我从未听说过这样做的实际理由。请记住,Chef 已经对订单敏感,您不要使用:before 强制执行订单,它仅适用于这种升级情况。

    【讨论】:

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