11

I'd like to declare a resource that I want to run multiple times on notification and only on notification. How can I prevent the resource to run on its own after it is declared?

Is there some way to check if there is a notification present, so I can run something like "only_if :notified"?

TheCleaner
  • 32,822

2 Answers2

14

Here is an example where my execute resource is only converged when my directory resource converges:

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

execute 'custom command' do
  command 'echo foo'
  action :nothing
end

See https://docs.chef.io/chef/resources.html#notifications for more examples.

tbizzle
  • 141
12

Use action :nothing during declaration.