Hej,
próbuje jako skonfigurować logrotate dla rsysloga i nginxa w odrębie jednego taska, ale coś mi nie wychodzi. Task wrzuca konfiguracje korzystając z templatki.
W gorup_vars/all.yml mam ustawione logrotate_scripts
:
# logrotate
logrotate_scripts:
- name: nginx
path: /var/log/nginx/*.log
option:
- daily
- missingok
- maxsize 100M
- rotate 14
- compress
- delaycompress
- name: rsyslog
path: /var/log/syslog
option:
- weekly
- missingok
- maxsize 10M
- rotate 35
paths: /var/log/deamon.log
options:
- weekly
- missingok
- maxsize 100M
- rotate 14
Task:
- name: Setup logrotate.d scripts
template:
src: logrotate.d.j2
dest: "{{ logrotate_conf_dir }}{{ item.name }}"
with_items: "{{ logrotate_scripts }}"
when: logrotate_scripts is defined
Templatka pod nginxa, która działa (logrotate.d.j2):
{{ item.path }} {
{% if item.options is defined -%}
{% for option in item.options -%}
{{ option }}
{% endfor -%}
{% endif %}
{%- if item.scripts is defined -%}
{%- for name, script in item.scripts.iteritems() -%}
{{ name }}
{{ script }}
endscript
{% endfor -%}
{% endif -%}
}
Templatka pod rsysloga, która działa dla niego, ale przy nginxie się wysypuje, bo szuka drugiej ścieżki, której nginx nie ma:
{% for path in item.path -%}
{{ path }}
{% endfor %}
{
{% if item.options is defined -%}
{% for option in item.options -%}
{{ option }}
{% endfor -%}
{% endif %}
{%- if item.scripts is defined -%}
{%- for name, script in item.scripts.iteritems() -%}
{{ name }}
{{ script }}
endscript
{% endfor -%}
{% endif -%}
}
{% for paths in item.paths -%}
{{ paths }}
{% endfor %}
{
{% if item.option is defined -%}
{% for options in item.option -%}
{{ options }}
{% endfor -%}
{% endif %}
{%- if item.scripts is defined -%}
{%- for name, script in item.scripts.iteritems() -%}
{{ name }}
{{ script }}
endscript
{% endfor -%}
{% endif -%}
}
I teraz szukam jakiegoś mądrego sposobu, żeby w ramach jednej templatki zrobić to tak, żeby działało zarówno dla nginxa z jedną ściezką jak i dla rsysloga z dwoma.
A może lepiej jakoś przerobić tego taska?