diff --git a/roles/vega_common/files/etc/logrotate.d/rsyslog b/roles/vega_common/files/etc/logrotate.d/rsyslog new file mode 100644 index 0000000..837783b --- /dev/null +++ b/roles/vega_common/files/etc/logrotate.d/rsyslog @@ -0,0 +1,26 @@ +/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 +{ + size 5G + rotate 3 + daily + missingok + notifempty + compress + delaycompress + sharedscripts + postrotate + /usr/lib/rsyslog/rsyslog-rotate + endscript +} diff --git a/roles/vega_common/files/usr/lib/rsyslog/rsyslog-rotate b/roles/vega_common/files/usr/lib/rsyslog/rsyslog-rotate new file mode 100644 index 0000000..ef3954b --- /dev/null +++ b/roles/vega_common/files/usr/lib/rsyslog/rsyslog-rotate @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ -d /run/systemd/system ]; then + systemctl kill -s HUP rsyslog.service +fi diff --git a/roles/vega_common/handlers/main.yaml b/roles/vega_common/handlers/main.yaml new file mode 100644 index 0000000..bacfff8 --- /dev/null +++ b/roles/vega_common/handlers/main.yaml @@ -0,0 +1,8 @@ +--- +- name: Restart logrotate + ansible.builtin.service: + state: restarted + daemon_reload: true + enabled: true + name: logrotate + listen: "Restart logrotate" diff --git a/roles/vega_common/tasks/logrotate.yaml b/roles/vega_common/tasks/logrotate.yaml new file mode 100644 index 0000000..e826da8 --- /dev/null +++ b/roles/vega_common/tasks/logrotate.yaml @@ -0,0 +1,31 @@ +--- +- name: Install logrotate + ansible.builtin.apt: + pkg: + - logrotate + retries: 3 + delay: 3 + register: logrotate_install + until: logrotate_install is succeeded + +- name: Copy logrotate scripts + ansible.builtin.copy: + src: "{{- item -}}" + dest: "/{{- item -}}" + owner: root + group: root + mode: '0755' + notify: "Restart logrotate" + with_items: + - usr/lib/rsyslog/rsyslog-rotate + +- name: Copy log rotate configs + ansible.builtin.copy: + src: "{{- item -}}" + dest: "/{{- item -}}" + owner: root + group: root + mode: '0644' + notify: "Restart logrotate" + with_items: + - etc/logrotate.d/rsyslog diff --git a/roles/vega_common/tasks/main.yaml b/roles/vega_common/tasks/main.yaml index a9a4936..be65331 100644 --- a/roles/vega_common/tasks/main.yaml +++ b/roles/vega_common/tasks/main.yaml @@ -56,6 +56,9 @@ - name: Install dasel ansible.builtin.import_tasks: dasel.yaml +- name: Install logrotate + ansible.builtin.import_tasks: logrotate.yaml + - name: Set a hostname ansible.builtin.hostname: name: "{{- vega_common_custom_hostname -}}"