Below are my input.yaml
and my template.jinja
:
input.yaml:
animals:
my_pets:
- species:
name: "cat"
age: "28"
- species:
name: "dog"
age: "10"
template.jinja
{%- for pet in animals.my_pets %}
Type: {{ pet.species.name }}
Name: {{ pet.species.age }}
{%- endfor %}
The result should be like the input.yaml
animals:
my_pets:
- species:
name: "cat"
age: "28"
- species:
name: "dog"
age: "10"
For sure something is not right on my template as it doesn't render the expected structure but I don't find what.
I've made some modification and somehow it work, but not as intended.
new_input.yaml:
my_pets:
- species:
- name: "cat"
- age: "28"
- species:
- name: "dog"
- age: "10"
new_template.jinja:
my_pets:
{%- for intf in my_pets %}
{%- for i in intf.species %}
{%- for key,value in i.items() %}
- species:
- {{ key }}: "{{ value }}"
{%- endfor %}
{%- endfor %}
{%- endfor %}
The new_output is like this:
my_pets:
- species:
- name: "cat"
- species:
- age: "28"
- species:
- name: "dog"
- species:
- age: "10"
But it should be like this:
animals:
my_pets:
- species:
name: "cat"
age: "28"
- species:
name: "dog"
age: "10"