0

i have a dictionary in jinja:

  reservations:
test:
  - hw_address: 00:0c:29:60:F8:3D
    ip_addresses: 2001:db8:1::101
alpine:     
  - hw_address: 00:50:56:84:F4:B2
    ip_addresses: 2001:db8:1::102        
test_server:     
  - duid: 01:02:03:04:05:06:07:08:09:0A
    ip_addresses: 2001:db8:1::103
    prefixes: 2001:db8:2:abcd::/64
    hostname: foo.example.com

and I would like a result similar to this

{ "hw-address": "00:0c:29:60:F8:3D", "ip-addresses": [ "2001:db8:1::101" ] },
{ "hw-address": "00:50:56:84:F4:B2", "ip-addresses": [ "2001:db8:1::102" ] } 
{ "duid": "01:02:03:04:05:06:07:08:09:0A",
  "ip_addresses": ["2001:db8:1::103"],
  "prefixes": ["2001:db8:2:abcd::/64"],
  "hostname": "foo.example.com"
}

i tried dictsort, but i can't access the items

        {%- for vm_name, d in reservations | dictsort %}
        {{ vm_name }}
        {{ d }}
        {% endfor %}
OrangeDog
  • 36,653
  • 12
  • 122
  • 207
  • 1
    You might want to look into: https://stackoverflow.com/questions/25373154/how-to-iterate-through-a-list-of-dictionaries-in-jinja-template – Parzival Mar 29 '21 at 18:54
  • Does this answer your question? [How to iterate through a list of dictionaries in Jinja template?](https://stackoverflow.com/questions/25373154/how-to-iterate-through-a-list-of-dictionaries-in-jinja-template) – OrangeDog Feb 06 '22 at 11:12

0 Answers0