There are two things here:
1 :
>>> import yaml
>>> from pprint import pprint
>>> p1 = yaml.load("""
... ---
... PROVIDERS:
... PROV1:
... int: ge-0/1/1
... ipv4: 10.0.1.1/30
... PROV2:
... int: ge-0/1/2
... ipv4: 10.0.1.2/30
... """)
>>> pprint(p1)
{'PROVIDERS': {'PROV1': {'int': 'ge-0/1/1', 'ipv4': '10.0.1.1/30'},
'PROV2': {'int': 'ge-0/1/2', 'ipv4': '10.0.1.2/30'}}}
, 'PROVIDERS', 'PROV1' 'PROV2', . , ( ), , , , .
:
{%- for provider in PROVIDERS %}
PROVIDERS (, , , , , 'PROVIDERS' ), , , , :
{{ PROVIDERS[provider].int }}
{{ PROVIDERS[provider].ipv4 }}
YAML :
---
- id: PROV1
int: ge-0/1/1
ipv4: 10.0.1.1/30
- id: PROV2
int: ge-0/1/2
ipv4: 10.0.1.2/30
, . , , :
>>> p2 = yaml.load("""
... ---
... - id: PROV1
... int: ge-0/1/1
... ipv4: 10.0.1.1/30
... - id: PROV2
... int: ge-0/1/2
... ipv4: 10.0.1.2/30
... """)
>>> pprint(p2)
[{'int': 'ge-0/1/1', 'ipv4': '10.0.1.1/30', 'id': 'PROV1'},
{'int': 'ge-0/1/2', 'ipv4': '10.0.1.2/30', 'id': 'PROV2'}]
:
{%- for provider in PROVIDERS %}
{{ provider.id }}
{{ provider.int }}
{{ provider.ipv4 }}
{%- endfor %}
, , PROVIDERS , , YAML, , .