I want to execute an include tasks list until a certain condition is met, I do not have a fixed loop but execution depends upon a condition.
A sample play below
Tasks list playbook
tasks.yml
---
- name: "inc test-var {{ test_var }}"
set_fact:
test_var: "{{ test_var | int + 1 }} "
parent playbook parent.yml
---
- hosts: all
gather_facts: no
tasks:
- set_fact:
test_var: '1'
req_var: '4'
- name: "Test multi run of task"
include_tasks: ./includes/tasks.yml
register: versions_result
until: test_var is version(req_var, '<')
retries: 5
here I am expecting parent.yml tasks to run multiple times but it only run once.
Could some one point out what I am doing wrong and how to run a task multiple times until a condition is met.
Cheers,
One way to
include_tasksmultiple times is to loop over the range of numbers till it reaches the required number. However as you expect the "parent" playbook will not be run multiple times, the tasks file will be.Consider the below example:
Through my main playbook
parent.yml, I would like to runtasks1.ymlmultiple times (as defined inset_fact).And in my
tasks1.yml, I have a simpledebugmessage:Includes
tasks1.yml4 times and gives below output when I runansible-playbook parent.yml: