Possible to pass values back from an include_tasks set of tasks to main playbook?

I would like to trim a large playbook down by looping through the tasks using include_tasks in a parent playbook. However I need to be able to track the return code and stdout from those tasks in the parent playbook in order to determine overall play success. Is it possible to pass values back into the parent? When I do the following the loop_result only includes the values passed to include task but no values recorded in the tasks in include_tasks. I’d like to be able to collect each iteration to test the return code from the win_command and stdout in the main.yml.

tasks.yml

  • name: Powershell
    win_command: powershell.exe -executionpolicy bypass c:\scripts\somescript.ps1
    register: result

  • name: test
    debug:
    msg: “{%if result.rc == 0 %} success {% else %} fail”

main.yml
usual stuff…

  • name: loop
    include_tasks: tasks.yml
    register: loop_result
    loop: “{{ list }}”

You can use set_fact to extend an array of prior results with your new result. Behold:

---
# tasks.yml
- name: Powershell
  win_command: powershell.exe -executionpolicy bypass c:\scripts\somescript.ps1
  register: result

- name: Accumulate registered results
  ansible.builtin.set_fact:
    task_yml_results: "{{ task_yml_results | default([]) + [result] }}"

Cheers,