Handle mappings passed as dict or OrderedDict

This commit is contained in:
Gilles Dartiguelongue 2016-04-08 18:27:15 +02:00
parent 4c780c184e
commit 80645badee

View File

@ -1,19 +1,23 @@
# Managed by config management # Managed by config management
{% if data is mapping -%} {%- macro format_value(key, value) %}
{% for key, value in data.iteritems() -%} {#- Some settings, like virtual_alias_maps can take multiple values. Handle this case. -#}
{# Some settings, like virtual_alias_maps can take multiple values. Handle this case. -#} {%- if value is iterable and value is not string -%}
{% if value is iterable and value is not string -%} {%- for item in value %}
{% for item in value -%}
{{ key }} {{ item }} {{ key }} {{ item }}
{% endfor -%} {%- endfor %}
{% else -%} {%- else -%}
{{ key }} {{ value }} {{ key }} {{ value }}
{% endif -%} {%- endif -%}
{% endfor -%} {%- endmacro %}
{% else -%}
{# Some settings need order, handle OrderedDict -#} {%- if data is mapping %}
{% for item in data -%} {% for key, value in data.iteritems() %}
{{ item.keys()[0] }} {{ item.values()[0] }} {{ format_value(key, value) }}
{% endfor -%} {%- endfor -%}
{% endif -%} {%- else %}
{#- Some settings need order, handle OrderedDict #}
{% for item in data %}
{{ format_value(item.keys()[0], item.values()[0]) }}
{%- endfor -%}
{%- endif %}