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

12

Use action :nothing during declaration.

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.

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.