Any suggestions for structuring a playbook, perhaps with rescue and always?

Hi all,

I’m trying to sort out a playbook and have been reading about blocks, rescue, always. I’ve also tried using a handler with run_once. But I’m still struggling.

Here’s what I’m trying to achieve:

  1. I want to run some tasks on an inventory of nexus switches.
  2. I want to update a mongodb collection with the result of the tasks for each switch. I’ve written a module to do this.
  3. When all of the switches have been processed, I want to update the mongodb collection again with a summary of all of the results.

Does anyone have any suggestions for how to do something like this ?

This was my first attempt: