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
shell: "echo {{item.value.name}} is {{item.value.age}}"
with_dict: groups[group]
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/345bc816-73e9-4d6e-b417-acc1aac5ca29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.