# {{ ansible_managed }}

{% if lvm__config_base_version|d() %}
# lvm.conf based on lvm2 package version: {{ lvm__config_base_version }}

{% endif %}
{% set lvm__tpl_base = lvm__config_base %}
{% set lvm__tpl_config = lvm__config %}
{% macro print_content (key, value) %}
{% if value is not iterable %}
{% if value in [ 0, 1 ] %}
{% if value | bool %}
{{ key }} = 1
{% elif not value | bool %}
{{ key }} = 0
{% endif %}
{% elif value is number %}
{{ key }} = {{ value }}
{% endif %}
{% elif value is iterable %}
{% if value is string %}
{% if value[0:1] == "0" %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% endif %}
{% else %}
{% if value | length > 0 %}
{{ key }} = [ "{{ value | join('", "') }}" ]
{% else %}
{{ key }} = [ ]
{% endif %}
{% endif %}
{% endif %}
{% endmacro %}
{% macro print_section (name, content, mask) %}
{%   set seen_keys = [] %}
{{ name }} {
{%   for key, value in content.items() %}
{%     if value is mapping %}
{{ print_section (key, value, {}) | indent (4,true) }}
{%       set _ = seen_keys.append(key) %}
{%     else %}
{%       if key in mask.keys() %}
{{ print_content (key, mask[key]) | indent (4,true) }}
{%         set _ = seen_keys.append(key) %}
{%       else %}
{{ print_content (key, value) | indent (4,true) }}
{%         set _ = seen_keys.append(key) %}
{%       endif %}
{%     endif %}
{%   endfor %}
{%   if mask %}
{%     for key, value in mask.items() %}
{%       if key not in seen_keys %}
{{ print_content ( key, value) | indent (4,true) }}
{%       endif %}
{%     endfor %}
{%   endif %}
}
{% endmacro %}
{% set seen_sections = [] %}
{% for section in lvm__tpl_base.keys() | sort %}
{% if section in lvm__tpl_config.keys() %}
{{ print_section (section, lvm__tpl_base[section], lvm__tpl_config[section]) }}
{% set _ = seen_sections.append(section) %}
{% else %}
{{ print_section (section, lvm__tpl_base[section], {}) }}
{% set _ = seen_sections.append(section) %}
{% endif %}
{% endfor %}
{% for section in lvm__tpl_config.keys() | sort %}
{% if section not in seen_sections %}
{{ print_section (section, lvm__tpl_config[section], {}) }}
{% endif %}
{% endfor %}

