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"?


Use action :nothing during declaration.

| improve this answer | |

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

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

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.