From 4ac8535dd7dbb05249fdce15223e62392a0bf80e Mon Sep 17 00:00:00 2001 From: Eric Veiras Galisson Date: Thu, 12 Jul 2018 12:44:01 +0200 Subject: [PATCH] new possibility to configure a job giving the raw content to store as a file --- logrotate/jobs.sls | 10 ++++++++-- pillar.example | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/logrotate/jobs.sls b/logrotate/jobs.sls index eb2b9ab..17da253 100644 --- a/logrotate/jobs.sls +++ b/logrotate/jobs.sls @@ -6,16 +6,20 @@ include: - logrotate {% for key, value in jobs.items() %} + {% set contents = value.get('contents', False) %} logrotate-{{ key }}: file.managed: - name: {{ logrotate.include_dir }}/{{ key.split("/")[-1] }} - - source: salt://logrotate/templates/job.tmpl - - template: jinja - user: {{ salt['pillar.get']('logrotate:config:user', logrotate.user) }} - group: {{ salt['pillar.get']('logrotate:config:group', logrotate.group) }} - mode: {{ salt['pillar.get']('logrotate:config:mode', '644') }} - require: - pkg: logrotate-pkg + {% if contents %} + - contents: {{ contents | yaml_encode }} + {% else %} + - source: salt://logrotate/templates/job.tmpl + - template: jinja - context: {% if value is mapping %} path: {{ value.get('path', []) }} @@ -24,4 +28,6 @@ logrotate-{{ key }}: path: {{ key }} data: {{ value }} {% endif %} + {% endif %} {%- endfor -%} + diff --git a/pillar.example b/pillar.example index 7108c36..4786d99 100644 --- a/pillar.example +++ b/pillar.example @@ -47,3 +47,23 @@ logrotate: - postrotate - /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true - endscript + nginx: + contents: | + /var/log/nginx/*.log{ + weekly + missingok + compress + delaycompress + notifempty + create 0640 www-data adm + sharedscripts + prerotate + if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ + run-parts /etc/logrotate.d/httpd-prerotate; \ + fi \ + endscript + postrotate + invoke-rc.d nginx rotate >/dev/null 2>&1 + endscript + } +