1
0
Fork 0

Merge pull request #32 from daks/jobs_contents

Adding possibility to submit raw content to configure a job
This commit is contained in:
Daniel Wallace 2018-07-31 09:07:11 -05:00 committed by GitHub
commit 6575a95764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 4 deletions

View File

@ -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 -%}

View File

@ -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
}

View File

@ -0,0 +1,71 @@
# encoding: utf-8
title 'Test logrotate jobs configuration'
describe file('/etc/logrotate.d/error') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
# FIXME
#its('content') { should include '/tmp/var/log/mysql/error' }
its('content') { should include 'weekly' }
its('content') { should include 'missingok' }
its('content') { should include 'rotate 52' }
its('content') { should include 'compress' }
its('content') { should include 'delaycompress' }
its('content') { should include 'notifempty' }
its('content') { should include 'create 640 root adm' }
its('content') { should include 'sharedscripts' }
end
describe file('/etc/logrotate.d/mysql') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
its('content') { should include '/tmp/var/log/mysql/*.log' }
its('content') { should include 'weekly' }
its('content') { should include 'missingok' }
its('content') { should include 'rotate 52' }
its('content') { should include 'compress' }
its('content') { should include 'delaycompress' }
its('content') { should include 'notifempty' }
its('content') { should include 'create 640 root adm' }
its('content') { should include 'sharedscripts' }
end
describe file('/etc/logrotate.d/syslog') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
its('content') { should include '/var/log/cron' }
its('content') { should include '/var/log/maillog' }
its('content') { should include '/var/log/messages' }
its('content') { should include '/var/log/secure' }
its('content') { should include '/var/log/spooler' }
its('content') { should include '/var/log/slapd.log' }
its('content') { should include 'sharedscripts' }
its('content') { should include 'postrotate' }
its('content') { should include 'sharedscripts' }
end
describe file('/etc/logrotate.d/nginx') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
its('content') { should include '/var/log/nginx/*.log' }
its('content') { should include 'weekly' }
its('content') { should include 'missingok' }
its('content') { should include 'compress' }
its('content') { should include 'delaycompress' }
its('content') { should include 'prerotate' }
its('content') { should include 'if [ -d /etc/logrotate.d/httpd-prerotate ]; then \\' }
its('content') { should include ' run-parts /etc/logrotate.d/httpd-prerotate; \\' }
its('content') { should include ' fi \\' }
its('content') { should include 'postrotate' }
its('content') { should include ' invoke-rc.d nginx rotate >/dev/null 2>&1' }
end

View File

@ -1,5 +1,5 @@
name: shorewall
title: Shorewall Profile
name: logrotate
title: Logrotate Profile
maintainer: Eric Veiras Galisson
copyright: Eric Veiras Galisson
copyright_email: eric AT sietch-tabr DOT com