# Possible to pass values back from an include\_tasks set of tasks to main playbook?

**URL:** <https://forum.ansible.com/t/possible-to-pass-values-back-from-an-include-tasks-set-of-tasks-to-main-playbook/38775>\
**Category:** Ansible Project\
**Created:** [May 13, 2024, 3:29pm UTC](https://forum.ansible.com/t/possible-to-pass-values-back-from-an-include-tasks-set-of-tasks-to-main-playbook/38775 "2024-05-13T15:29:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_Trimm](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@Sean\_Trimm](https://forum.ansible.com/u/Sean_Trimm)\
**Post date:** [May 13, 2024, 3:29pm UTC](https://forum.ansible.com/t/possible-to-pass-values-back-from-an-include-tasks-set-of-tasks-to-main-playbook/38775/1 "2024-05-13T15:29:55Z")

</div>

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 }}”

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [May 14, 2024, 11:12am UTC](https://forum.ansible.com/t/possible-to-pass-values-back-from-an-include-tasks-set-of-tasks-to-main-playbook/38775/2 "2024-05-14T11:12:29Z")

</div>

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

```auto
---
# 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,
