NSD: Avoid duplicating the 'list expansion' code in template

This commit is contained in:
Baptiste Jonglez 2016-03-27 18:16:46 +02:00
parent a5d94f234a
commit b4dd5c9066

View File

@ -1,31 +1,30 @@
{# If value is a list, expand it by printing several (key, value) pairs. #}
{# Otherwise, just print the (key, value) pair unchanged. #}
{% macro expand_list(key, value) -%}
{% if value is string or value is number %}
{{ key }}: "{{ value }}"
{% else %}
{% for subvalue in value %}
{{ key }}: "{{ subvalue }}"
{% endfor %}
{% endif %}
{%- endmacro %}
# NSD configuration, automatically generated by Ansible. # NSD configuration, automatically generated by Ansible.
# Do not edit by hand! # Do not edit by hand!
server: server:
{% if nsd_common_config is defined %} {% if nsd_common_config is defined %}
# Common configuration # Common configuration
{% for key, value in nsd_common_config.iteritems() %} {% for key, value in nsd_common_config.iteritems() -%}
{% if value is string or value is number %} {{ expand_list(key, value) }}
{{ key }}: "{{ value }}" {%- endfor %}
{% else %}
{% for subvalue in value %}
{{ key }}: "{{ subvalue }}"
{% endfor %}
{% endif %}
{% endfor %}
{% endif %} {% endif %}
{% if nsd_local_config is defined %} {% if nsd_local_config is defined %}
# Local configuration # Local configuration
{% for key, value in nsd_local_config.iteritems() %} {% for key, value in nsd_local_config.iteritems() -%}
{% if value is string or value is number %} {{ expand_list(key, value) }}
{{ key }}: "{{ value }}" {%- endfor %}
{% else %}
{% for subvalue in value %}
{{ key }}: "{{ subvalue }}"
{% endfor %}
{% endif %}
{% endfor %}
{% endif %} {% endif %}