How to pass information in a workflow and reuse it in a "summary play" (debug)

Let’s assume I have a hostgroup of 6 hosts and I need to run a playbook (play1) two times in sequence for different hosts in that group because of depenencies between some hosts.

I’d like to gather information within both plays and pass that information further.
In a last step I’d like to reuse the previously collected information in order to create a summary over all hosts (in both plays 1_a and 1_b); here for debugging (later I’d
like to use that information to create an html report with a Jinja2 templating).

The problem I have is the information in the debug messages are not per host. It seems it stores just the output from one host and reuses it for all others in the
inventory in the last play (see sample output of the report_comment variable below → just one of those 6 servers had that exception).

I’m not sure if using the set_stats module is the best way to reach what I’d like?
Or would it be better to store the information in temp. files on localhost and read the information in the last play?

Any ideas or suggestions how to reach my goal would be much appreciated!

Workflow Template

-------------| |-------------| |-------------|
play1_a | —> | play1_b | —> | summary |

-------------| |-------------| |-------------|

play1_a:

I worked around this by creating a dictionary in set_stats. The dictionary consists of a key set to hostname and a value set to my per-host data (can be anything including another dictionary). Downstream plays get the dictionary and each host can find its own data using its hostname as the key into that dict.

- name: Create and Add items to dictionary
  set_stats: 
    data:
      my_dict: "{{ my_dict | default({}) | combine ({ item.key : item.value }) }}"
  with_items:
    - { "key": "{{ inventory_hostname_short }}" , "value": {
          "var_a" : "{{ var_a_val }}",
          "var_b" : "{{ var_b_val }}",
          "var_c" : "{{ var_c_val }}"
        }
      }

The downstream playbooks can use my_dict[inventory_hostname_short] to access their specific data.

Walter

Hi Walter
Thanks a lot for your input! That seems to work for me as well - you made my day :wink:
Much appreciated!
Phil