【发布时间】: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