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
{% if data is mapping -%}
{% for key, value in data.iteritems() -%}
{# Some settings, like virtual_alias_maps can take multiple values. Handle this case. -#}
{% if value is iterable and value is not string -%}
{% for item in value -%}
{%- macro format_value(key, value) %}
{#- Some settings, like virtual_alias_maps can take multiple values. Handle this case. -#}
{%- if value is iterable and value is not string -%}
{%- for item in value %}
{{ key }} {{ item }}
{% endfor -%}
{% else -%}
{%- endfor %}
{%- else -%}
{{ key }} {{ value }}
{% endif -%}
{% endfor -%}
{% else -%}
{# Some settings need order, handle OrderedDict -#}
{% for item in data -%}
{{ item.keys()[0] }} {{ item.values()[0] }}
{% endfor -%}
{% endif -%}
{%- endif -%}
{%- endmacro %}
{%- if data is mapping %}
{% for key, value in data.iteritems() %}
{{ format_value(key, value) }}
{%- endfor -%}
{%- else %}
{#- Some settings need order, handle OrderedDict #}
{% for item in data %}
{{ format_value(item.keys()[0], item.values()[0]) }}
{%- endfor -%}
{%- endif %}