Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add logrotate #30

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions roles/vega_common/files/etc/logrotate.d/rsyslog
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions roles/vega_common/files/usr/lib/rsyslog/rsyslog-rotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

if [ -d /run/systemd/system ]; then
systemctl kill -s HUP rsyslog.service
fi
8 changes: 8 additions & 0 deletions roles/vega_common/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Restart logrotate
ansible.builtin.service:
state: restarted
daemon_reload: true
enabled: true
name: logrotate
listen: "Restart logrotate"
31 changes: 31 additions & 0 deletions roles/vega_common/tasks/logrotate.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions roles/vega_common/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}"
Expand Down
Loading