tasks:
- name: cleaning up the logs that exceed 5Mb
command: cat /dev/null > {{ item }}
when: filesize(/var/log/apache2/access.log) > 5Mb---
- hosts: "{{ host | default('localhost') }}"
vars:
- loglist:
- /var/log/wtmp
- /var/log/apache2/access.log
- /var/log/apache2/error.log
tasks:
- name: erase old downloaded .deb archives
command: apt autoclean
- name: get log size info
stat: path={{ item }}
with_items: loglist
register: logsize
- name: cleaning up logs that exceed 5Mb
debug: "msg='{{ item.item }}: {{ item.stat.size }}'"
with_items: logsize.results
when: item.stat.size > 5*(1024**2)
Now that I think of it, wouldn't running logrotate with a specific config from cron every few mins be better?
Brian Coca