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,627
  • 26
  • 132
  • 191
Victor Hahn
  • 113
  • 1
  • 1
  • 7

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.

StephenKing
  • 952
  • 1
  • 8
  • 18
tbizzle
  • 141
  • 3
12

Use action :nothing during declaration.

StephenKing
  • 952
  • 1
  • 8
  • 18