Skip to content

Instantly share code, notes, and snippets.

@nathanhoel
Created March 24, 2016 15:05
Show Gist options
  • Save nathanhoel/f5433a0d9cfe2e717c71 to your computer and use it in GitHub Desktop.
Save nathanhoel/f5433a0d9cfe2e717c71 to your computer and use it in GitHub Desktop.
Chef notification and subscription ordering
# These resources will essentially run in this order.
# You must understand how the converge step in chef works before this will make sense.
# Even if you defined these resources in another order, this will still print the
# statements in order (FIRST, SECOND, THIRD, ...)
# The :before timers always occur before the resource doing the notifying/subscribed to.
# The :immediate/:immediately timers always occur after the resource doing the notifying/subscribed to.
# When there are notifications and subscriptions with the same timing on a resource
# notifications will fire before subscriptions.
ruby_block "n-test-before" do
block do
Chef::Log.info("FIRST")
end
action :nothing
end
ruby_block "n-test-sub-before" do
block do
Chef::Log.info("SECOND")
end
action :nothing
subscribes :run, 'ruby_block[n-test]', :before
end
ruby_block "n-test" do
block do
Chef::Log.info("THIRD")
end
notifies :run, 'ruby_block[n-test-before]', :before
notifies :run, 'ruby_block[n-test-immediate]', :immediately
end
ruby_block "n-test-immediate" do
block do
Chef::Log.info("FOURTH")
end
action :nothing
end
ruby_block "n-test-sub-immediate" do
block do
Chef::Log.info("FIFTH")
end
action :nothing
subscribes :run, 'ruby_block[n-test]', :immediately
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment