keepalived-formula/keepalived/templates/config.jinja
2017-01-19 07:48:26 -05:00

35 lines
1.0 KiB
Django/Jinja

{%- set key = 0 -%}
{%- set value = 1 -%}
{%- set carryovers = ['vrrp_script'] -%}
{%- macro keepalived_config(data, carryover='', recurse=-1) -%}
{%- set recurse = recurse + 1 -%}
{%- if data is none -%}
{{- '\n' -}}
{%- elif data is string or data is number -%}
{{- data }}{{ '\n' -}}
{%- else -%}
{%- if recurse > 0 -%}
{{- '{\n' -}}
{%- endif -%}
{%- if data is mapping -%}
{%- for item in data|dictsort -%}
{%- if item[key] in carryovers -%}
{{- keepalived_config(item[value], carryover=item[key]) -}}
{%- else -%}
{%- if carryover -%}
{{- carryover }}{{ ' ' -}}
{%- endif -%}
{{- item[key] }} {{ keepalived_config(item[value], recurse=recurse) -}}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{%- for item in data -%}
{{- keepalived_config(item) -}}
{%- endfor -%}
{%- endif -%}
{%- if recurse > 0 -%}
{{- '}\n' -}}
{%- endif -%}
{%- endif -%}
{%- endmacro -%}