I want to include tasks based on the condition set inside the task.
tasks:
- name: SET INIT STATUS
set_facts:
passed: true
- name: INCLUDE TASKS WITH LOOP
include_tasks: update_status.yml
loop: [1, 2, 3]
when: passed
update_status.yml:
- name: OUTPUT THE STATUS
debug: msg="ITEM: {{item}} has status {{passed}}"
- name: UPDATE the Status
set_fact:
passed: false
What I expected that it will only run once for item 1 because after it runs, it will change the status to false and then it failed the condition check. But it actually run 3 time so looks like it does not check the status during the loop again.
Here is the output
TASK: [SET INIT STATUS]
ok: [localhost]
TASK: [INCLUDE TASKS WITH LOOP]
included: simple.yml for localhost
included: simple.yml for localhost
included: simple.yml for localhost
TASK: [OUTPUT THE STATUS]
ok: [localhost] => {
"msg": ITEM 1 has status True
}
TASK: [UPDATE the Status]
ok: [localhost]
TASK: [OUTPUT THE STATUS]
ok: [localhost] => {
"msg": ITEM 2 has status False
}
TASK: [UPDATE the Status]
ok: [localhost]
TASK: [OUTPUT THE STATUS]
ok: [localhost] => {
"msg": ITEM 3 has status False
}
TASK: [UPDATE the Status]
ok: [localhost]