# logrotate web nginx # 1. configure logrotate # 2. configure crontab: crontab: 0 2 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx - hosts: web-nginx vars: logrotate_scripts: - name: web-nginx-logrotate paths: - "/Data/logs/nginx/*.log" - "/Data/logs/nginx/nginx-activity-yoho-cn/*.log" - "/Data/logs/nginx/activity-yoho-cn/*.log" options: - daily - dateext - rotate 30 - olddir /Data/logs/nginx/backup - notifempty - compress - sharedscripts scripts: postrotate: "[ ! -f /usr/local/openresty/nginx/logs/nginx.pid ] || kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid`" remote_user: root roles: - logrotate tasks: - name: remove existed precated crontab shell: "crontab -u root -l |grep -v 'logrotate' |crontab -u root -" - name: create cron jobs for logrotate cron: name: "rotate for web nginx logs" minute: "0" hour: "2" job: "/usr/sbin/logrotate -f /etc/logrotate.d/web-nginx-logrotate" become_user: "root"