Last active
May 2, 2016 15:17
-
-
Save nacx/9cbcede2d3a48d739cdd16b22a268a4f to your computer and use it in GitHub Desktop.
Chef resource dynamic notification
This file contains hidden or 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
# This has the intended behavior, but I need to declare the log[bar] at the end | |
log "bar" do | |
action :nothing | |
end | |
log "foo" do | |
begin | |
notifies :write, resources("log[bar]").to_s, :immediately | |
rescue Chef::Exceptions::ResourceNotFound | |
Chef::Log.info("No log[bar] resource present. Skipping notification.") | |
end | |
end | |
# OUTPUT: | |
# * log[bar] action nothing (skipped due to action :nothing) | |
# * log[foo] action write | |
# | |
# * log[bar] action write |
This file contains hidden or 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
# I want this code to behave just as the code in the previous file, but | |
# also need to keep the resource declaration in this order | |
log "foo" do | |
begin | |
notifies :write, resources("log[bar]").to_s, :immediately | |
rescue Chef::Exceptions::ResourceNotFound | |
Chef::Log.info("No log[bar] resource present. Skipping notification.") | |
end | |
end | |
log "bar" do | |
action :nothing | |
end | |
# OUTPUT: | |
# * log[foo] action write | |
# | |
# * log[bar] action nothing (skipped due to action :nothing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment