diff --git a/keepalived/templates/keepalived.jinja b/keepalived/templates/keepalived.jinja index 60bf7c3..52d8f53 100644 --- a/keepalived/templates/keepalived.jinja +++ b/keepalived/templates/keepalived.jinja @@ -11,24 +11,30 @@ default=keepalived_defaults, merge=True) -%} -{%- macro config_entries(data, indents) -%} +{%- set groupings = ['vrrp_script', 'vrrp_sync_group', 'vrrp_instance', + 'virtual_server_group', 'virtual_server', 'real_server'] -%} +{%- macro config_entries(data, indents, carryover='') -%} {%- if data is string or data is number -%} {{ data|string|indent(indents, True) }}{{ '\n' }} {%- else -%} - {%- if indents != 0 -%} + {%- if indents != 0 and not carryover -%} {{- "{\n" -}} {%- endif -%} {%- if data is mapping -%} {%- for entry in data|dictsort -%} + {%- if entry[0] in groupings -%} +{{- config_entries(entry[1], indents + 2, carryover=entry[0]) -}} + {%- else -%} {{ entry[0]|indent(indents, True) }} {{- config_entries(entry[1], indents + 2) -}} + {%- endif -%} {%- endfor -%} {%- else -%} {%- for entry in data -%} {{- config_entries(entry, indents) -}} {%- endfor -%} {%- endif -%} - {%- if indents != 0 -%} + {%- if indents != 0 and not carryover -%} {{ '}'|indent(indents - 2, True) }}{{ '\n' }} {%- endif -%} {%- endif -%}