From 8fb48f722567ce7866e5cf09005fc82346498430 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sun, 23 Oct 2016 22:01:51 -0400 Subject: [PATCH] Getting the special entries added. --- keepalived/templates/keepalived.jinja | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 -%}