finding first host meeting a condition

Hey all-

I need to find the first host in the inventory running a particular process. I can query the hosts to look for the process using a shell pipeline and register the output in a variable (call it ps_output). But I’m stuck on how to iterate over the hosts, examining the value of ps_output, and stopping when I have found the first one. I don’t see a built in filter for this (maybe I need to write one?), I’ve struck out with templating, and I currently have it working with a complicated mess of storing the hostvars in a file and processing it with an external python script, but I have to believe there’s an easier way. Any suggestions?

Rob

Nevermind; figured this out. Was actually pretty simple. I declared a variable as an empty string, iterated over the hosts w/ hostvars, updated the variable with the item, and used when: (variable | length > 0 ) and (ps_output | length > 0). Including the variable in the when: test was key.

Rob