Ansible Community,
I'm using a conditional include statement to call a task file which has a task that uses a "with_dict" loop. When the include statement conditional fails, I'd like the task in "option.yml" to be skipped as the task would result in an error anyway.
When this is run, I get an error "with_dict expects a dict" since there is no dictionary "groups[{{ grps[2] }}]". Why does Ansible try to evaluate the task at all since it should be skipped because of the include conditional?
Ideally, there would be a way to use a "with_items" loop with an include statement, but I am aware that that is intentionally not allowed.
(Note: I know this is a terrible example of how/when to use an include statement, but it shows the gist of how the error occurs. My actual usage is much more complicated.)
## variables
---
people:
admins:
alice:
name: Alice Anderson
age: 24
bob:
name: Bob Brown
age: 29
devs:
chris:
name: Chris Campbell
age: 34
groups:
- admins
- devs
## file main.yml
---
- debug: var=groups
- include: option.yml
vars:
group: "{{groups[2]}}"
when: "2 < groups|length"
## file option.yml
---
- name: Print person info
with_dict: groups[group]