keepalived-formula/keepalived/templates/keepalived.jinja

64 lines
2.1 KiB
Plaintext
Raw Normal View History

2015-07-30 08:55:31 +02:00
# keepalived configuration
#
# **** DO NOT EDIT THIS FILE ****
#
# This file is managed by Salt.
# Any changes will be overwritten.
2016-10-24 01:17:58 +02:00
{{ '\n' }}
2016-11-08 19:48:11 +01:00
{#
Macro Explanation:
This is a recursive macro that takes the type of entry and determines how
it is suppose to appear in the configuration file. Strings and numbers
are just written out. Lists and hashes are placed inside if couple of
parenthesis. It also takes into account the special groupings like
vrrp_instance and virtual_server. Any additional data from a list or a
hash is then processed by calling the macro again.
Forced carriage returns and use of jinjas indent are only there to make
the final file more human readable. They serve no other function.
#}
2016-10-24 02:50:06 +02:00
{%- import_yaml 'keepalived/defaults.yaml' as keepalived_defaults -%}
2016-10-24 00:56:24 +02:00
{%- set keepalived_final_values = salt.pillar.get(
2016-10-24 01:29:26 +02:00
'keepalived',
2016-10-24 00:56:24 +02:00
default=keepalived_defaults,
2016-10-24 02:50:06 +02:00
merge=True) -%}
2016-10-24 00:56:24 +02:00
2016-10-24 04:01:51 +02:00
{%- set groupings = ['vrrp_script', 'vrrp_sync_group', 'vrrp_instance',
'virtual_server_group', 'virtual_server', 'real_server'] -%}
{%- macro config_entries(data, indents, carryover='') -%}
2016-10-24 05:25:07 +02:00
{%- if data is string or data is number -%}
2016-10-24 11:34:39 +02:00
{{- data|string|indent(indents, True) }}{{ '\n' -}}
2016-10-24 05:25:07 +02:00
{%- elif data is none -%}
2016-10-24 11:34:39 +02:00
{{- '\n' -}}
2016-10-24 02:11:55 +02:00
{%- else -%}
2016-10-24 04:01:51 +02:00
{%- if indents != 0 and not carryover -%}
2016-10-24 11:34:39 +02:00
{{- " {\n" -}}
{%- endif -%}
2016-10-24 02:11:55 +02:00
{%- if data is mapping -%}
{%- for entry in data|dictsort -%}
2016-10-24 04:01:51 +02:00
{%- if entry[0] in groupings -%}
2016-10-24 11:34:39 +02:00
{{- config_entries(entry[1], indents, carryover=entry[0]) -}}
2016-10-24 04:01:51 +02:00
{%- else -%}
2016-10-24 04:12:47 +02:00
{%- if carryover -%}
2016-10-24 11:34:39 +02:00
{{- carryover|indent(indents, True) }}{{ ' ' }}
2016-10-24 04:12:47 +02:00
{%- endif -%}
2016-10-24 11:34:39 +02:00
{{- entry[0]|indent(indents, True) }}
{{- config_entries(entry[1], indents + 2) -}}
2016-10-24 04:01:51 +02:00
{%- endif -%}
2016-10-24 02:11:55 +02:00
{%- endfor -%}
2016-10-24 02:37:27 +02:00
{%- else -%}
{%- for entry in data -%}
2016-10-24 11:34:39 +02:00
{{- config_entries(entry, indents) -}}
2016-10-24 02:37:27 +02:00
{%- endfor -%}
2016-10-24 02:11:55 +02:00
{%- endif -%}
2016-10-24 04:01:51 +02:00
{%- if indents != 0 and not carryover -%}
2016-10-24 11:34:39 +02:00
{{- '}'|indent(indents - 2, True) }}{{ '\n' }}
{%- endif -%}
2016-10-24 00:56:24 +02:00
{%- endif -%}
{%- endmacro -%}
2016-10-24 01:03:11 +02:00
2016-10-24 01:44:51 +02:00
{{ config_entries(keepalived_final_values, 0) }}