# {{ ansible_managed }}

{% if logrotate__options %}
{{ logrotate__options | regex_replace('\n$','') }}
{% endif %}
{% if logrotate__group_options %}
{{ logrotate__group_options | regex_replace('\n$','') }}
{% endif %}
{% if logrotate__host_options %}
{{ logrotate__host_options | regex_replace('\n$','') }}
{% endif %}
{% if logrotate__default_options %}
{{ logrotate__default_options | regex_replace('\n$','') }}
{% endif %}

{% macro print_config(section) %}
{%   if section.state is undefined or section.state != 'absent' %}
{%     if section.comment|d() %}
{{ section.comment | regex_replace('\n$','') | comment(prefix='', postfix='') -}}
{%     endif %}
{%     if section.log|d() %}
{%       if section.log is string %}
{{ section.log }} {
{%       else %}
{%         if section.log|length <= 2 %}
{{ section.log | join(" ") }} {
{%         else %}
{%           for element in section.log %}
{{ element }}
{%           endfor %}
{
{%         endif %}
{%       endif %}
{%     elif section.logs|d() %}
{%       if section.logs is string %}
{{ section.logs }} {
{%       else %}
{%         if section.logs|length <= 2 %}
{{ section.logs | join(" ") }} {
{%         else %}
{%           for element in section.logs %}
{{ element }}
{%           endfor %}
{
{%         endif %}
{%       endif %}
{%     endif %}
{%     if section.options|d() %}
{{ section.options | regex_replace('\n$','') | indent(4, true) }}
{%     endif %}
{%     if section.firstaction|d() %}
    firstaction
{{ section.firstaction | regex_replace('\n$','') | indent(8, true) }}
    endscript
{%     endif %}
{%     if section.prerotate|d() %}
    prerotate
{{ section.prerotate | regex_replace('\n$','') | indent(8, true) }}
    endscript
{%     endif %}
{%     if section.postrotate|d() %}
    postrotate
{{ section.postrotate | regex_replace('\n$','') | indent(8, true) }}
    endscript
{%     endif %}
{%     if section.preremove|d() %}
    preremove
{{ section.preremove | regex_replace('\n$','') | indent(8, true) }}
    endscript
{%     endif %}
{%     if section.lastaction|d() %}
    lastaction
{{ section.lastaction | regex_replace('\n$','') | indent(8, true) }}
    endscript
{%     endif %}
}
{%   endif %}
{% endmacro %}
{% for item in logrotate__default_config %}
{%   if item.sections|d() %}
{%     for section in item.sections %}
{%       if (section.log|d() or section.logs|d() or section.filename|d()) and section.state|d('present') != 'absent' %}
{{ print_config(section) | regex_replace('\n$','') }}
{%         if not loop.last %}

{%         endif %}
{%       endif %}
{%     endfor %}
{%   else %}
{%     if (item.log|d() or item.logs|d() or item.filename|d()) and item.state|d('present') != 'absent' %}
{{ print_config(item) | regex_replace('\n$','') }}
{%       if not loop.last %}

{%       endif %}
{%     endif %}
{%   endif %}
{% endfor %}
