I am trying to iterate multiple tasks based on the result from one of the tasks in the child yml file.
Since, looping on blocks is not possible, I have included all the tasks in task file and including that child file from main playbook.
main.yml:
- hosts: host01
vars:
state: "running"
tasks:
- name: include tasks file
include_tasks: ./abc.yml
when: state == "running"
with_sequence: start=1 end=3
abc.yml:
- name: get the value from the system
shell: echo something
register: out
- name: override the variable state as completed
set_fact:
state: "completed"
when: out.rc == 0
Failure case: so here, i should iterate the include tasks file until I get state as "completed"(try max three times) . If not fail the Playbook.
success case: If out.rc results zero, the variable state is overriden with "completed" in first iteration itself but still its executing two more times instead of exiting.
What am I missing here? or anyother way we can iterate multiple tasks based on output of one of the tasks?