Presently I have a chef recipe whereby I post messages to chat, inside a loop:
artifacts.each do |artifactItem|
# Deploy the artifact
#...
# Post to chat
chat_post "deployed artifact #{artifact_name}"
end
The result on my chat is like this:
chef [BOT]
deployed artifact A
chef [BOT]
deployed artifact B
chef [BOT]
deployed artifact C
I am wondering - is there an easy "queue" mechanism in chef, where I can queue up my deployment messages, and post them all at once (when my recipe completes) ? If so how would the code look.
The easiest way to do this would be to use the delayed notifications system.
artifacts.each do |artifactItem|
# Deploy the artifact
#...
# Post to chat
r = chat_post "deployed artifact #{artifact_name}" do
action :nothing
end
ruby_block "notification for #{artifact_name}" do
block { }
notifies :someaction, r
end
end
Or something like that, make sure you check what action to use for the notification (whatever the default action on the chat_post
resource is. Also this assumes chat_post
is a resource and not some kind of helper method. If it's not a resource, you might need two ruby_blocks
.