70 lines
2.2 KiB
Django/Jinja
70 lines
2.2 KiB
Django/Jinja
**** start of template ****
|
|
|
|
0) display the config_context:
|
|
|
|
top level context item:
|
|
|
|
{{ config_context }}
|
|
|
|
selecting the best unicorn with config_context['best_unicorn'][0]:
|
|
|
|
{{ config_context['best_unicorn'][0] }}
|
|
|
|
accessing a key pair injected into the jinja environment global variables:
|
|
(in this case the config_context printed out in human readable yaml format)
|
|
|
|
{% filter indent(width=3) %}
|
|
{{ pretty_config_context }}
|
|
{% endfilter %}
|
|
|
|
loop through the config_context variable in jinja:
|
|
|
|
{% for key, value in config_context.items() %}
|
|
{{ key }}:{{ value }}
|
|
{% endfor %}
|
|
|
|
1) source template ./device/{{ config_context['device'] }}.yml
|
|
|
|
2) source template ./device/region/{{ config_context['region'] }}.yml
|
|
|
|
3) source template ./device/site/{{ config_context['site'] }}.yml
|
|
|
|
4) source template ./device/role/<files>.yml
|
|
these contexts happens to be a list in the inventory
|
|
files under this directory happen to have the same weight(they dont have to)
|
|
thus these files do not have the same keys as they would clash
|
|
|
|
{% if config_context['gabbys_doll_house'] %}
|
|
gabbys_doll_house = {{ config_context['gabbys_doll_house'] }}
|
|
{% endif %}
|
|
|
|
{% if config_context['octonaughts'] %}
|
|
octonaughts = {{ config_context['octonaughts'] }}
|
|
{% endif %}
|
|
|
|
notice best_unicorn is in the all.yml context and router.yml context
|
|
router.yml has a higher precedence(lower weight value)
|
|
|
|
{% if config_context['best_unicorn'] %}
|
|
{% for entry in config_context['best_unicorn'] %}
|
|
- {{ entry }}
|
|
{% endfor %}
|
|
{% endif %}
|
|
|
|
{% if config_context['harry_potter'] %}
|
|
harry_potter = {{ config_context['harry_potter'] }}
|
|
{% endif %}
|
|
|
|
notice cbeebies_schedule is in the all.yml context and vpn.yml context
|
|
all.yml context is weighted last/-1, any other context will overwrite it
|
|
vpn.yml has a higher precedence(lower weight value)
|
|
|
|
{% if config_context['cbeebies_schedule'] %}
|
|
cbeebies_schedule = {{ config_context['cbeebies_schedule'] }}
|
|
{% endif %}
|
|
|
|
4) source template ./device/role/all.yml
|
|
nothing is rendered using this context, all variables are overwritten by contexts with higher precedence
|
|
this would be a good place to put service accounts in ACLs or legal disclaimers
|
|
|
|
**** end of template **** |