diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a63ba31 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vagrant +*log diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..9339b39 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,15 @@ +--- +#logrotate.conf +logrotate_when: 'weekly' +logrotate_keep: '4' +logrotate_what_todo: 'create' +logrotate_compress: 'false' +logrotate_configs: + - name: 'rsyslog' + when: 'daily' + keep: '7' + second_when: 'weekly' + second_keep: '4' + - name: 'zabbix-agent' + when: 'weekly' + keep: '12' diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..3d408f3 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,11 @@ +--- + +- name: '[APT] - Install logrotate' + apt: + name: 'logrotate' + +- name: '[Logrotate] - Deploy all configs' + template: + src: etc/logrotate.d/{{ item.name }}.j2 + dest: /etc/logrotate.d/{{ item.name }} + with_items: "{{ logrotate_configs }}" diff --git a/templates/etc/logrotate.conf.j2 b/templates/etc/logrotate.conf.j2 new file mode 100644 index 0000000..64e9ec0 --- /dev/null +++ b/templates/etc/logrotate.conf.j2 @@ -0,0 +1,36 @@ +# see "man logrotate" for details +# rotate log files weekly +{{ logrotate_when }}weekly + +# keep 4 weeks worth of backlogs +rotate {{ logrotate_keep }}rotate 4 + +# create new (empty) log files after rotating old ones +{{ logrotate_what_todo }}create + +# uncomment this if you want your log files compressed +{% if logrotate_compress == 'true' %} +compress +{% else %} +#compress +{% endif %} + +# packages drop log rotation information into this directory +include /etc/logrotate.d + +# no packages own wtmp, or btmp -- we'll rotate them here +/var/log/wtmp { + missingok + monthly + create 0664 root utmp + rotate 1 +} + +/var/log/btmp { + missingok + monthly + create 0660 root utmp + rotate 1 +} + +# system-specific logs may be configured here diff --git a/templates/etc/logrotate.d/amavis.j2 b/templates/etc/logrotate.d/amavis.j2 new file mode 100644 index 0000000..4cf33b4 --- /dev/null +++ b/templates/etc/logrotate.d/amavis.j2 @@ -0,0 +1,10 @@ +/var/log/amavis/amavis.log { + su amavis amavis + {{ item.when }} + rotate {{ item.keep }} + compress + nomail + delaycompress + missingok + notifempty +} diff --git a/templates/etc/logrotate.d/apt.j2 b/templates/etc/logrotate.d/apt.j2 new file mode 100644 index 0000000..853696f --- /dev/null +++ b/templates/etc/logrotate.d/apt.j2 @@ -0,0 +1,11 @@ +/var/log/apt/history.log +/var/log/apt/term.log +{ + {{ item.when }} + rotate {{ item.keep }} + compress + delaycompress + missingok + notifempty + create 0640 root root +} diff --git a/templates/etc/logrotate.d/clamav.j2 b/templates/etc/logrotate.d/clamav.j2 new file mode 100644 index 0000000..944186e --- /dev/null +++ b/templates/etc/logrotate.d/clamav.j2 @@ -0,0 +1,11 @@ +/var/log/clamav/clamav.log +/var/log/clamav/freshclam.log +{ + {{ item.when }} + rotate {{ item.keep }} + compress + delaycompress + missingok + notifempty + create 0640 clamav adm +} diff --git a/templates/etc/logrotate.d/fail2ban.j2 b/templates/etc/logrotate.d/fail2ban.j2 new file mode 100644 index 0000000..3dfcaae --- /dev/null +++ b/templates/etc/logrotate.d/fail2ban.j2 @@ -0,0 +1,10 @@ +/var/log/fail2ban.log +{ + {{ item.when }} + rotate {{ item.keep }} + compress + delaycompress + missingok + notifempty + create 0640 root root +} diff --git a/templates/etc/logrotate.d/general.j2 b/templates/etc/logrotate.d/general.j2 new file mode 100644 index 0000000..1cf451f --- /dev/null +++ b/templates/etc/logrotate.d/general.j2 @@ -0,0 +1,13 @@ +/var/log/alternatives.log +/var/log/dpkg.log +/var/log/fail2ban.log +/var/log/razor-agent.log +{ + {{ item.when }} + rotate {{ item.keep }} + compress + delaycompress + missingok + notifempty + create 0640 root root +} diff --git a/templates/etc/logrotate.d/hubzilla.j2 b/templates/etc/logrotate.d/hubzilla.j2 new file mode 100644 index 0000000..fcc4387 --- /dev/null +++ b/templates/etc/logrotate.d/hubzilla.j2 @@ -0,0 +1,10 @@ +/var/log/hubzilla/hubzilla.log +{ + {{ item.when }} + rotate {{ item.keep }} + compress + delaycompress + missingok + notifempty + create 0640 www-data www-data +} diff --git a/templates/etc/logrotate.d/jitsi.j2 b/templates/etc/logrotate.d/jitsi.j2 new file mode 100644 index 0000000..e58281b --- /dev/null +++ b/templates/etc/logrotate.d/jitsi.j2 @@ -0,0 +1,13 @@ +/var/log/jitsi/jicofo.log +/var/log/jitsi/jvb.log +{ + {{ item.when }} + rotate {{ item.when }} + compress + delaycompress + postrotate + systemctl restart jvb + endscript + sharedscripts + missingok +} diff --git a/templates/etc/logrotate.d/mysql-server.j2 b/templates/etc/logrotate.d/mysql-server.j2 new file mode 100644 index 0000000..4d26f3f --- /dev/null +++ b/templates/etc/logrotate.d/mysql-server.j2 @@ -0,0 +1,24 @@ +# - I put everything in one block and added sharedscripts, so that mysql gets +# flush-logs'd only once. +# Else the binary logs would automatically increase by n times every day. +# - The error log is obsolete, messages go to syslog now. +/var/log/mysql.log /var/log/mysql/mysql.log +/var/log/mysql/mariadb-slow.log +/var/log/mysql/mysql-slow.log +{ + {{ item.when }} + rotate {{ item.keep }} + missingok + create 640 mysql adm + compress + sharedscripts + postrotate + test -x /usr/bin/mysqladmin || exit 0 + + if [ -f `my_print_defaults --mysqld | grep -oP "pid-file=\K[^$]+"` ]; then + # If this fails, check debian.conf! + mysqladmin --defaults-file=/etc/mysql/debian.cnf --local flush-error-log \ + flush-engine-log flush-general-log flush-slow-log + fi + endscript +} diff --git a/templates/etc/logrotate.d/nginx.j2 b/templates/etc/logrotate.d/nginx.j2 new file mode 100644 index 0000000..f5bce9c --- /dev/null +++ b/templates/etc/logrotate.d/nginx.j2 @@ -0,0 +1,18 @@ +/var/log/nginx/*.log { + {{ item.when }} + missingok + rotate {{item.keep }} + 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 +} diff --git a/templates/etc/logrotate.d/php-fpm.j2 b/templates/etc/logrotate.d/php-fpm.j2 new file mode 100644 index 0000000..ff06f56 --- /dev/null +++ b/templates/etc/logrotate.d/php-fpm.j2 @@ -0,0 +1,11 @@ +/var/log/php*-fpm.log { + rotate {{ item.keep }} + {{ item.when }} + missingok + notifempty + compress + delaycompress + postrotate + /usr/lib/php/php8.0-fpm-reopenlogs + endscript +} diff --git a/templates/etc/logrotate.d/php5-fpm.j2 b/templates/etc/logrotate.d/php5-fpm.j2 new file mode 100644 index 0000000..3b5f1b0 --- /dev/null +++ b/templates/etc/logrotate.d/php5-fpm.j2 @@ -0,0 +1,11 @@ +/var/log/php5-fpm.log { + rotate {{ item.keep }} + {{ item.when }} + missingok + notifempty + compress + delaycompress + postrotate + /usr/lib/php5/php5-fpm-reopenlogs + endscript +} diff --git a/templates/etc/logrotate.d/php7.0-fpm.j2 b/templates/etc/logrotate.d/php7.0-fpm.j2 new file mode 100644 index 0000000..763572e --- /dev/null +++ b/templates/etc/logrotate.d/php7.0-fpm.j2 @@ -0,0 +1,11 @@ +/var/log/php7.0-fpm.log { + rotate {{ item.keep }} + {{ item.when }} + missingok + notifempty + compress + delaycompress + postrotate + /usr/lib/php/php7.0-fpm-reopenlogs + endscript +} diff --git a/templates/etc/logrotate.d/php7.2-fpm.j2 b/templates/etc/logrotate.d/php7.2-fpm.j2 new file mode 100644 index 0000000..4e7dcb2 --- /dev/null +++ b/templates/etc/logrotate.d/php7.2-fpm.j2 @@ -0,0 +1,11 @@ +/var/log/php7.2-fpm.log { + rotate {{ item.keep }} + {{ item.when }} + missingok + notifempty + compress + delaycompress + postrotate + /usr/lib/php/php7.2-fpm-reopenlogs + endscript +} diff --git a/templates/etc/logrotate.d/php7.3-fpm.j2 b/templates/etc/logrotate.d/php7.3-fpm.j2 new file mode 100644 index 0000000..9d2bd39 --- /dev/null +++ b/templates/etc/logrotate.d/php7.3-fpm.j2 @@ -0,0 +1,11 @@ +/var/log/php7.3-fpm.log { + rotate {{ item.keep }} + {{ item.when }} + missingok + notifempty + compress + delaycompress + postrotate + /usr/lib/php/php7.3-fpm-reopenlogs + endscript +} diff --git a/templates/etc/logrotate.d/php8.0-fpm.j2 b/templates/etc/logrotate.d/php8.0-fpm.j2 new file mode 100644 index 0000000..6a2b365 --- /dev/null +++ b/templates/etc/logrotate.d/php8.0-fpm.j2 @@ -0,0 +1,11 @@ +/var/log/php8.0-fpm.log { + rotate {{ item.keep }} + {{ item.when }} + missingok + notifempty + compress + delaycompress + postrotate + /usr/lib/php/php8.0-fpm-reopenlogs + endscript +} diff --git a/templates/etc/logrotate.d/php8.1-fpm.j2 b/templates/etc/logrotate.d/php8.1-fpm.j2 new file mode 100644 index 0000000..c7b31e6 --- /dev/null +++ b/templates/etc/logrotate.d/php8.1-fpm.j2 @@ -0,0 +1,11 @@ +/var/log/php8.1-fpm.log { + rotate {{ item.keep }} + {{ item.when }} + missingok + notifempty + compress + delaycompress + postrotate + /usr/lib/php/php8.1-fpm-reopenlogs + endscript +} diff --git a/templates/etc/logrotate.d/postgresql-common.j2 b/templates/etc/logrotate.d/postgresql-common.j2 new file mode 100644 index 0000000..137d9cf --- /dev/null +++ b/templates/etc/logrotate.d/postgresql-common.j2 @@ -0,0 +1,10 @@ +/var/log/postgresql/*.log { + {{ item.when }} + rotate {{ item.keep }} + copytruncate + delaycompress + compress + notifempty + missingok + su root root +} diff --git a/templates/etc/logrotate.d/prosody.j2 b/templates/etc/logrotate.d/prosody.j2 new file mode 100644 index 0000000..a3cf045 --- /dev/null +++ b/templates/etc/logrotate.d/prosody.j2 @@ -0,0 +1,13 @@ +/var/log/prosody/prosody.log +/var/log/prosody/prosody.err { + {{ item.when }} + rotate {{ item.when }} + compress + delaycompress + create 640 prosody adm + postrotate + service prosody reload + endscript + sharedscripts + missingok +} diff --git a/templates/etc/logrotate.d/redis-server.j2 b/templates/etc/logrotate.d/redis-server.j2 new file mode 100644 index 0000000..b6db1c0 --- /dev/null +++ b/templates/etc/logrotate.d/redis-server.j2 @@ -0,0 +1,7 @@ +/var/log/redis/redis-server.log { + {{ item.when }} + missingok + rotate {{ item.keep }} + compress + notifempty +} diff --git a/templates/etc/logrotate.d/rsyslog.j2 b/templates/etc/logrotate.d/rsyslog.j2 new file mode 100644 index 0000000..2aa5c2d --- /dev/null +++ b/templates/etc/logrotate.d/rsyslog.j2 @@ -0,0 +1,25 @@ +/var/log/syslog +/var/log/mail.info +/var/log/mail.warn +/var/log/mail.err +/var/log/mail.log +/var/log/daemon.log +/var/log/kern.log +/var/log/auth.log +/var/log/user.log +/var/log/lpr.log +/var/log/cron.log +/var/log/debug +/var/log/messages +{ + rotate {{ item.keep }} + {{ item.when }} + missingok + notifempty + compress + delaycompress + sharedscripts + postrotate + /usr/lib/rsyslog/rsyslog-rotate + endscript +} diff --git a/templates/etc/logrotate.d/tomcat.j2 b/templates/etc/logrotate.d/tomcat.j2 new file mode 100644 index 0000000..5a91670 --- /dev/null +++ b/templates/etc/logrotate.d/tomcat.j2 @@ -0,0 +1,8 @@ +/var/log/tomcat9/catalina.out { + copytruncate + {{ item.when }} + rotate {{ item.keep }} + compress + missingok + create 640 tomcat9 adm +} diff --git a/templates/etc/logrotate.d/tomcat8.j2 b/templates/etc/logrotate.d/tomcat8.j2 new file mode 100644 index 0000000..d2e81e5 --- /dev/null +++ b/templates/etc/logrotate.d/tomcat8.j2 @@ -0,0 +1,8 @@ +/var/log/tomcat8/catalina.out { + copytruncate + {{ item.when }} + rotate {{ item.keep }} + compress + missingok + create 640 tomcat8 adm +} diff --git a/templates/etc/logrotate.d/tomcat9.j2 b/templates/etc/logrotate.d/tomcat9.j2 new file mode 100644 index 0000000..5a91670 --- /dev/null +++ b/templates/etc/logrotate.d/tomcat9.j2 @@ -0,0 +1,8 @@ +/var/log/tomcat9/catalina.out { + copytruncate + {{ item.when }} + rotate {{ item.keep }} + compress + missingok + create 640 tomcat9 adm +} diff --git a/templates/etc/logrotate.d/uwsgi.j2 b/templates/etc/logrotate.d/uwsgi.j2 new file mode 100644 index 0000000..7efd33a --- /dev/null +++ b/templates/etc/logrotate.d/uwsgi.j2 @@ -0,0 +1,9 @@ +""/var/log/uwsgi/*.logi" "/var/log/uwsgi/*/*.log" { + copytruncate + {{ item.when }} + rotate {{ item.keep }} + compress + delaycompress + missingok + notifempty +} diff --git a/templates/etc/logrotate.d/zabbix-agent.j2 b/templates/etc/logrotate.d/zabbix-agent.j2 new file mode 100644 index 0000000..03076ee --- /dev/null +++ b/templates/etc/logrotate.d/zabbix-agent.j2 @@ -0,0 +1,9 @@ +/var/log/zabbix/zabbix_agentd.log { + {{ item.when }} + rotate {{ item.keep }} + compress + delaycompress + missingok + notifempty + create 0640 zabbix zabbix +} diff --git a/templates/etc/logrotate.d/zabbix-server.j2 b/templates/etc/logrotate.d/zabbix-server.j2 new file mode 100644 index 0000000..f14c15b --- /dev/null +++ b/templates/etc/logrotate.d/zabbix-server.j2 @@ -0,0 +1,9 @@ +/var/log/zabbix/zabbix_server.log { + {{ item.when }} + rotate {{ item.keep }} + compress + delaycompress + missingok + notifempty + create 0640 zabbix zabbix +}