i read a yml file with lookup and try to loop over the dict.
yml file:
---
root:
children_one:
attribute_one: true
attribute_two: foo
children_two:
attribute_one: false
attribute_two: bar
children_three:
attribute_one: false
attribute_two: foo`
in the ansible playbook i will print out all children with the attribute_two when the attribute_one is false
- ansible.builtin.debug:
msg: "{{ item }} - {{ item.attribute_two }}"
with_items: "{{ (lookup('template', 'file.yml.j2') | from_yaml).root }}"
when: (item.attribute_one | lower) == 'false'
the error say there ist no attribute attribute_one.
how can i resolve it?
Thanks
Use
with_dict. This converts the dictionary to a list. The type ofattribute_oneis boolean. This simplifies the conditiongives
You'll get the same using
loopand the filterdict2itemsThis can be further improved by simplifying the label and rejecting
attribute_onein the pipegives
Example of a complete playbook for testing