Hi,
My goal is to iterate items on a json list response, and find the good item. The good item is the one on which all test tasks succeed. Tests are done in the included_task yaml file.
But my playbook do not work, i am unable to break the outer calling loop task if i found the good item from within the called included task list.
The outer task :
- name: set item_ok
set_fact:
item_ok: false
- name: call included task for each items
include_tasks: "tests_on_item.yml"
loop: "{{ item_list }}"
loop_control:
loop_var: outer_item
when: item_ok is false
and inner task , tests_on_item.yml:
---
- name: tests on item
vars:
task_status: "OK"
block:
- name: Show item_ok value
debug:
msg: "item_ok: {{ item_ok }}"
- name: test 1
assert:
that:
- blah blah
fail_msg: "blah "
- name: test 2
assert:
that: blah blah
fail_msg: "blah blah"
- name: item found
set_fact:
item_ok: true
# if one of the tests fails, the rescue directive is executed ans this included inner tasks yaml file is ended. The outer calling task will compute the next item.
rescue:
- name: set var error
vars:
task_status: "ERROR"
debug:
msg : "task_status: ERROR"
when: task_status == 'OK'
Have you an idea?
Regards,
Gaetan
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/6fa80b33-76d1-2860-5b67-f2c246520701%40gmail.com.