keepalived-formula/keepalived/templates/config.jinja

35 lines
1.0 KiB
Plaintext
Raw Normal View History

2017-01-19 03:29:15 +01:00
{%- set key = 0 -%}
{%- set value = 1 -%}
2017-01-19 13:48:26 +01:00
{%- set carryovers = ['vrrp_script'] -%}
{%- macro keepalived_config(data, carryover='', recurse=-1) -%}
2017-01-19 02:40:19 +01:00
{%- set recurse = recurse + 1 -%}
2017-01-19 01:51:16 +01:00
{%- if data is none -%}
2017-01-19 02:40:19 +01:00
{{- '\n' -}}
{%- elif data is string or data is number -%}
{{- data }}{{ '\n' -}}
2017-01-19 03:47:53 +01:00
{%- else -%}
2017-01-19 02:40:19 +01:00
{%- if recurse > 0 -%}
{{- '{\n' -}}
{%- endif -%}
2017-01-19 03:47:53 +01:00
{%- if data is mapping -%}
{%- for item in data|dictsort -%}
2017-01-19 13:48:26 +01:00
{%- 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 -%}
2017-01-19 03:47:53 +01:00
{%- endfor -%}
{%- else -%}
{%- for item in data -%}
{{- keepalived_config(item) -}}
{%- endfor -%}
2017-01-19 03:38:51 +01:00
{%- endif -%}
{%- if recurse > 0 -%}
2017-01-19 13:48:26 +01:00
{{- '}\n' -}}
2017-01-19 03:38:51 +01:00
{%- endif -%}
2017-01-19 01:51:16 +01:00
{%- endif -%}
{%- endmacro -%}