{%- set key = 0 -%} {%- set value = 1 -%} {%- macro keepalived_config(data, recurse=-1) -%} {%- set recurse = recurse + 1 -%} {%- if data is none -%} {{- '\n' -}} {%- elif data is string or data is number -%} {{- data }}{{ '\n' -}} {%- elif data is mapping -%} {%- if recurse > 0 -%} {{- '{\n' -}} {%- endif -%} {%- for item in data|dictsort -%} {{- item[key] }} {{ keepalived_config(item[value], recurse) -}} {%- endfor -%} {%- if recurse > 0 -%} {{- '}\n' -}} {%- endif -%} {%- else -%} {%- if recurse > 0 -%} {{- '{\n' -}} {%- endif -%} {%- for item in data -%} {{- keepalived_config(item) -}} {%- endfor -%} {%- if recurse > 0 -%} {{- '}\n' -}} {%- endif -%} {%- endif -%} {%- endmacro -%}