Chef:如何仅在通知时运行资源?

Vic*_*ahn 11 chef

我想声明一个资源,我想在通知时多次运行并且仅在通知时运行。如何防止资源在声明后自行运行?

有什么方法可以检查是否存在通知,以便我可以运行“only_if :notified”之类的内容?

小智 14

这是一个示例,其中我的execute资源仅在我的directory资源收敛时才收敛:

directory '/opt/foo' do
  action :create
  notifies :run, 'execute[custom command]', :immediately
end

execute 'custom command' do
  command 'echo foo'
  action :nothing
end
Run Code Online (Sandbox Code Playgroud)

有关更多示例,请参阅https://docs.chef.io/chef/resources.html#notifications


Ste*_*ing 12

action :nothing申报时使用。