2025-03-10 14:05:30
---
- name: Configure logrotate for MariaDB
hosts: mariadb_servers
become: yes
tasks:
- name: Install necessary packages
yum:
name:
- zstd
- logrotate
state: present
- name: Create logrotate configuration for MariaDB
blockinfile:
path: /etc/logrotate.d/mariadb
block: |
/var/log/mysql/* {
daily
missingok
notifempty
maxsize 1G
compress
compresscmd /usr/bin/zstd
compressext .zst
delaycompress
sharedscripts
postrotate
if test -x /usr/bin/mysqladmin && /usr/bin/mysqladmin ping &>/dev/null; then
/usr/bin/mysqladmin flush-error-log flush-engine-log flush-general-log flush-slow-log
fi
endscript
olddir /tmp
}
mode: '0644'
notify: restart logrotate
- name: Ensure logrotate service is running
service:
name: crond
state: started
enabled: yes
- name: Ensure logrotate is executed daily
cron:
name: "logrotate"
minute: "0"
hour: "0"
job: "/usr/sbin/logrotate /etc/logrotate.conf"
handlers:
- name: restart logrotate
service:
name: crond
state: restarted
Back to list