{# Copyright (C) 2015-2020 Maciej Delmanowski <drybjed@gmail.com>
 # Copyright (C) 2015-2020 DebOps <https://debops.org/>
 # SPDX-License-Identifier: GPL-3.0-only
 #}
# {{ ansible_managed }}

{% if item.comment|d() %}
{{   item.comment | regex_replace('\n$', '') | comment }}
{% endif %}
{% if item.raw|d() %}
{%   if item.state|d('present') == 'comment' %}
{{     '{}'.format(item.raw | regex_replace('\n$', '') | comment(prefix='', decoration='#', postfix='')) -}}
{%   else %}
{{     '{}'.format(item.raw | regex_replace('\n$', '')) }}
{%   endif %}
{% elif item.options|d() %}
{%   for element in item.options %}
{%     if element.state|d('present') not in [ 'absent', 'ignore', 'init' ] %}
{%       if element.comment|d() %}
{%         if not loop.first %}

{%         endif %}
{{         element.comment | regex_replace('\n$', '') | comment }}
{%       endif %}
{%       if element.state|d('present') == 'comment' %}
{{         '{}'.format(element.raw | regex_replace('\n$', '') | comment(prefix='', decoration='#', postfix='')) -}}
{%       else %}
{{         '{}'.format(element.raw | regex_replace('\n$', '')) }}
{%       endif %}
{%     endif %}
{%   endfor %}
{% endif %}
