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

up vote 12 down vote accepted

Use action :nothing during declaration.

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.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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