Notify only if file changed with arg?

Trying to send msg notification with a loop where the file name changes - need notified resource to get file name? In example below ‘current_deploy_file’ is not always correct (probably updated before ruby_block notify is run?)

current_deploy_file = ""
node[‘vhm_chef_scripts’][‘chef_deploy_files’].each do |deploy_file|
current_deploy_file = deploy_file
cookbook_file “#{chef_scripts_home}/#{deploy_file}” do
source deploy_file
action :create_if_missing
notifies :run, ‘ruby_block[send_update_msg]’, :immediately

ruby_block “send_update_msg” do
action :nothing
block do
send_kafka_monitor_msg(“Copy Chef deploy support file ‘#{current_deploy_file}’ to #{chef_scripts_home}”)

Quickest thought: create your ruby block items in the same loop with current_deploy_filename in the resource name. Then your notify for file foo can reference send_update_message_foo and each gets a unique message.


–Jp Robinson

Here are some options that I have used in the past:

  1. Put the ruby block in the loop, and name it uniquely with the file name. (easiest)
    * Remember that the ruby_block is also a resource, so you have added it to the resource collection only once.
  2. Write a custom resource for this special functionality (that’s probably best)

Keeping ruby_block resource within the loop and uniquely naming it based on the file name worked. Thanks.