我有以下厨师食谱。
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和:立即指令。
依我之见,以下是执行顺序。
转到bind-utils,但由于:before指令而跳至再次执行'yum-makecache'并运行它。
由于'yum-makecache'中的:immediatelyn而运行文件'message'
但是实际输出并不像'bind-utils'在'yum-makecache'之前运行
答案 0 :(得分:0)
before
通知非常严格,基本上仅用于在无法升级正在运行的服务的平台上更新程序包/文件之前停止服务。将进一步的通知挂起的时间肯定会做不合逻辑的事情,因为我从未听说过这样做的实际原因,所以我们不测试也不关心它的行为。请记住,Chef已经对订单敏感,您无需使用:before
来强制执行订单,它仅适用于这种升级情况。