Use notify to trigger a loop across an array

We are trying to split a string on a comma and then run an execute resource once for each value in the resulting array.

That part is working. The problem is that we are trying to have this trigger after a notify instead of running every time.

This code works but runs every time.

node.run_state['myapp_secrets'][:QMGR].split.each do |mq_server|
  execute 'start myapp instance' do
    user node['myapp']['jar']['username']
    cwd '/opt/myapp/'
    environment({ 'QMGR' => mq_server,
    command "java -jar /opt/myapp/myapp-all.jar > /dev/null &"

The problem is that if we notify the execute resource itself it only runs once (and the QMGR environment variable is unset.)

And we can't notify node.run_state['myapp_secrets'][:QMGR].split.each because it's straight ruby code and not a resource.

Regardless of the raw Ruby, typically with an execute resource you need to build your own guard because execute is not naturally idempotent.


We were trying to use notify with action :nothing.
But a guard might actually solve my problem.

I ended up moving my logic into a bash script I built with a template.