Created
March 24, 2016 15:05
-
-
Save nathanhoel/f5433a0d9cfe2e717c71 to your computer and use it in GitHub Desktop.
Chef notification and subscription ordering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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