@ -95,13 +95,32 @@ If a required variable has not been set, you can skip or fail using Jinja2's
This is especially useful in combination with the conditional import of vars
files (see below).
Note that when combining `when` with `with_items` (see :doc:`playbooks_loops`), be aware that the `when` statement is processed separately for each item. This is by design::
.._loops_and_conditionals:
Loops and Conditionals
``````````````````````
Combining `when` with `with_items` (see :doc:`playbooks_loops`), be aware that the `when` statement is processed separately for each item. This is by design::
tasks:
- command: echo {{ item }}
with_items: [ 0, 2, 4, 6, 8, 10 ]
when: item > 5
If you need to skip the whole task depending on the loop variable being defined, used the `|default` filter to provide an empty iterator::
- command: echo {{ item }}
with_items: "{{ mylist|default([]) }}"
when: item > 5
If using `with_dict` which does not take a list::
- command: echo {{ item.key }}
with_dict: "{{ mydict|default({}) }}"
when: item.value > 5
.._loading_in_custom_facts:
Loading in Custom Facts
```````````````````````
@ -115,6 +134,8 @@ there will be accessible to future tasks::