Dvi*_*evy 3 ruby chef-infra chef-recipe
我很新Chef.我有一个安装配方,sendmail它完成我的配置.我注意到Chef每次运行都会重启服务.那是因为我正在运行一个execute调用会话重启的人.
它看起来像这样:
execute "hashAccess" do
command "makemap hash /etc/mail/access < /etc/mail/access"
notifies :restart, "service[sendmail]"
end
Run Code Online (Sandbox Code Playgroud)
我只有在access文件更新时才需要调用它.
template "/etc/mail/access" do
source "access.erb"
mode "0644"
notifies :run, "execute[hashAccess]"
end
Run Code Online (Sandbox Code Playgroud)
更新文件时,execute会调用两次.两个资源都在同一个配方中,当我尝试define hashAccess收到错误时
ERROR: Cannot find a resource for define on amazon version 2013.09
Run Code Online (Sandbox Code Playgroud)
如何使执行资源仅在被调用时运行?
您应该添加action :nothing到执行资源.
execute "hashAccess" do
command "makemap hash /etc/mail/access < /etc/mail/access"
action :nothing
notifies :restart, "service[sendmail]"
end
Run Code Online (Sandbox Code Playgroud)
这样它就不会被执行,除非被其他资源通知.
| 归档时间: |
|
| 查看次数: |
753 次 |
| 最近记录: |