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,
—
Todd

On 5/13/24 11:29 AM, Sean Trimm wrote:
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 received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fdf28c14-555b-43f1-9da3-aa0036800fbdn%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/fdf28c14-555b-43f1-9da3-aa0036800fbdn%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Todd

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/90302a53-295c-4721-8cef-8687189588e9%40gmail.com.

Reply via email to