system-config/playbooks/roles/logrotate/tasks/main.yaml
Ian Wienand d4a96a421b logrotate: better rotation options
The extant "logrotate_daily" varaible doesn't really do anything and
isn't used.  Modify this to be able to set a range of rotation periods
or a size.

Update mirror rsync mirrors to rotate weekly, as often releases run
overnight and it's a pain to reconstruct.

Change-Id: I121dc5f4fe7f226b66d18b9ec39e7e3839be4d40
2019-10-01 09:00:53 +10:00

29 lines
1005 B
YAML

- name: Check for filename
fail:
msg: Must set logrotate_file_name for logfile to rotate
when: logrotate_file_name is not defined
- assert:
that:
- logrotate_frequency in ('hourly', 'daily', 'weekly', 'monthly', 'yearly', 'size')
fail_msg: Invalid logrotate_frequency
- assert:
that:
- logrotate_size
fail_msg: Must specify size for rotation
when: logrotate_frequency == 'size'
# Hash the full path to avoid any conflicts but remain idempotent.
# "/var/log/ansible/ansible.log" becomes "ansible.log.37237.conf" for example
- name: Create a unique config name
set_fact:
logrotate_generated_config_file_name: "{{ logrotate_file_name | basename }}.{{ (logrotate_file_name|hash('sha1'))[0:5] }}.conf"
- name: 'Install {{ logrotate_file_name }} rotatation config file'
template:
src: logrotate.conf.j2
dest: '/etc/logrotate.d/{{ logrotate_config_file_name|default(logrotate_generated_config_file_name) }}'
owner: root
group: root
mode: 0644