Skip to content

Instantly share code, notes, and snippets.

@nacx
Last active May 2, 2016 15:17
Show Gist options
  • Save nacx/9cbcede2d3a48d739cdd16b22a268a4f to your computer and use it in GitHub Desktop.
Save nacx/9cbcede2d3a48d739cdd16b22a268a4f to your computer and use it in GitHub Desktop.
Chef resource dynamic notification
# 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
# 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