From 1ee609a616a7702b637d97a7b89bd016f9b68385 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Thu, 19 Jan 2017 09:48:28 -0500 Subject: [PATCH] General cleanup. --- keepalived/templates/keepalived.jinja | 59 +-------------------------- pillar.example | 9 ++++ 2 files changed, 10 insertions(+), 58 deletions(-) diff --git a/keepalived/templates/keepalived.jinja b/keepalived/templates/keepalived.jinja index eb64ed2..b6fa7eb 100644 --- a/keepalived/templates/keepalived.jinja +++ b/keepalived/templates/keepalived.jinja @@ -6,67 +6,10 @@ # Any changes will be overwritten. {{ '\n' }} -{% import 'keepalived/templates/config.jinja' as config %} +{%- import 'keepalived/templates/config.jinja' as config -%} {%- import_yaml 'keepalived/defaults.yaml' as keepalived_defaults -%} {%- set keepalived_final_values = salt.pillar.get( 'keepalived', default=keepalived_defaults, merge=True) -%} {{ config.keepalived_config(keepalived_final_values) }} - -{# -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 jinja's indent are only there to make -the final file more human readable. They serve no other function. -#} -{# -{%- import_yaml 'keepalived/defaults.yaml' as keepalived_defaults -%} -{%- set keepalived_final_values = salt.pillar.get( - 'keepalived', - default=keepalived_defaults, - merge=True) -%} - -{%- 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' -}} - {%- elif data is none -%} - {{- '\n' -}} - {%- else -%} - {%- 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, carryover=entry[0]) -}} - {%- else -%} - {%- if carryover -%} - {{- carryover|indent(indents, True) }}{{ ' ' }} - {%- endif -%} - {{- 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 and not carryover -%} - {{- '}'|indent(indents - 2, True) }}{{ '\n' }} - {%- endif -%} - {%- endif -%} -{%- endmacro -%} - -{{ config_entries(keepalived_final_values, 0) }} -#} diff --git a/pillar.example b/pillar.example index 99b8db7..43fdd54 100644 --- a/pillar.example +++ b/pillar.example @@ -1,6 +1,15 @@ # # Example pillar configuration # +# Boolean entries must be placed stored as strings, otherwise it will show +# up as 1 or 0 in the config file. +# +# Anything that needs to be in quotes in the configuration file needs to +# be escaped in the yaml file. Otherwise the quotes will not appear in +# the config file. +# +# When order is important, put the entries into a yaml array or list. This +# could be used to place vrrp_script before vrrp_instance entries. # The following would generate the example file in RedHat based systems.