diff --git a/keepalived/templates/config.jinja b/keepalived/templates/config.jinja index 5a37e77..528d267 100644 --- a/keepalived/templates/config.jinja +++ b/keepalived/templates/config.jinja @@ -20,14 +20,15 @@ {{- keepalived_config(item[value], carryover=item[key], indent=indent) -}} {%- else -%} {%- set carryIndent = indentHolder -%} + {%- set forwardIndent = indentHolder -%} {%- if carryover -%} {{- carryover|indent(indentHolder, True) }}{{ ' ' -}} {%- set carryIndent = 0 -%} {%- endif -%} {%- if item[value] is string or item[value] is not iterable -%} - {%- set indent = 0 -%} + {%- set forwardIndent = 0 -%} {%- endif -%} - {{- item[key]|indent(carryIndent, True) }} {{ keepalived_config(item[value], recurse=recurse, indent=indent) -}} + {{- item[key]|indent(carryIndent, True) }} {{ keepalived_config(item[value], recurse=recurse, indent=forwardIndent) -}} {%- endif -%} {%- endfor -%} {%- else -%} diff --git a/test/test_keepalived_config.py b/test/test_keepalived_config.py index bfcbc85..c275160 100755 --- a/test/test_keepalived_config.py +++ b/test/test_keepalived_config.py @@ -104,5 +104,15 @@ class TestKeepalivedConfiguration(unittest.TestCase): result = 'virtual_server gizmo {\n real_server dumdums {\n barney rubble\n fred flintstone\n }\n}\n' self.renderTest(testdata, result) + def test_indent_nested_hashes(self): + testdata = {'flintstone': {'fred': {'role': {'family': 'father'}}}} + result = 'flintstone {\n fred {\n role {\n family father\n }\n }\n}\n' + self.renderTest(testdata, result) + + def test_indent_carryover_with_nested_hashes(self): + testdata = {'real_server': {'gizmo': {'another': 'day', 'dumdums': {'fred': 'flintstone', 'barney': 'rubble'}}}} + result = 'real_server gizmo {\n another day\n dumdums {\n barney rubble\n fred flintstone\n }\n}\n' + self.renderTest(testdata, result) + if __name__ == '__main__': unittest.main()