I am trying to run multiple tasks in a loop, but whenever I get an error inside the loop, ansible exits out of it. I want to be able to run the loop until the end of the list for each item. If something breaks for an item, the loop stops only for this item, not for the rest.
My inventory structure is json, but looks something like this:
webhost1:
items:
[item1, item2]
My ansible playbook does this:
- include: multiple_tasks_to_be_run_for_each_item.yml
with_items: items
The expected result is similar to running:
- shell: /bin/false
with_items:
- "1"
- "2"
- "3"
Even if it fails on the first item, it continues to run.
Please try with loop, loop_control and loop_var within Ansible Role, and let me know if it helps.
sample.yml
-----------
- include_tasks: "repeat.yml"
loop: "{{ list_of_values }}"
loop_control:
loop_var: var1
repeat.yml ( You can use the var1 inside the repeat.yml)
-----------
---
- name: Repeat Tasks
block:
- name : task 1
.........
- name : task 2
.........
Apparently this is the expected behaviour. Answer from github issue here.
This is working as intended. Use
block
andrescue
to control failure.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.