diff --git a/playbooks/roles/logrotate/README.rst b/playbooks/roles/logrotate/README.rst index 4250a90d70..c6bfeab9a1 100644 --- a/playbooks/roles/logrotate/README.rst +++ b/playbooks/roles/logrotate/README.rst @@ -36,8 +36,20 @@ not an exhaustive list of directives (contributions are welcome). .. zuul:rolevar:: logrotate_rotate :default: 7 -.. zuul:rolevar:: logrotate_daily - :default: yes +.. zuul:rolevar:: logrotate_frequency + :default: daily + + One of ``hourly``, ``daily``, ``weekly``, ``monthly``, ``yearly`` + or ``size``. + + If choosing ``size``, :zuul:rolevar::`logrotate.logrotate_size` must + be specified + +.. zuul:rolevar:: logrotate_size + :default: None + + Size; e.g. 100K, 10M, 1G. Only when + :zuul:rolevar::`logrotate.logrotate_frequency` is ``size``. .. zuul:rolevar:: logrotate_notifempty :default: yes diff --git a/playbooks/roles/logrotate/defaults/main.yaml b/playbooks/roles/logrotate/defaults/main.yaml index 8f9b815c24..f37e7d040f 100644 --- a/playbooks/roles/logrotate/defaults/main.yaml +++ b/playbooks/roles/logrotate/defaults/main.yaml @@ -3,5 +3,6 @@ logrotate_copytruncate: yes logrotate_delaycompress: yes logrotate_missingok: yes logrotate_rotate: 7 -logrotate_daily: yes +logrotate_frequency: daily +logrotate_size: None logrotate_notifempty: yes \ No newline at end of file diff --git a/playbooks/roles/logrotate/tasks/main.yaml b/playbooks/roles/logrotate/tasks/main.yaml index f2767d9f65..81bc7fa0c3 100644 --- a/playbooks/roles/logrotate/tasks/main.yaml +++ b/playbooks/roles/logrotate/tasks/main.yaml @@ -3,6 +3,17 @@ 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 diff --git a/playbooks/roles/logrotate/templates/logrotate.conf.j2 b/playbooks/roles/logrotate/templates/logrotate.conf.j2 index 0ed1039997..a1841c5706 100644 --- a/playbooks/roles/logrotate/templates/logrotate.conf.j2 +++ b/playbooks/roles/logrotate/templates/logrotate.conf.j2 @@ -12,8 +12,10 @@ missingok {% endif %} rotate {{ logrotate_rotate }} -{% if logrotate_daily %} - daily +{% if logrotate_frequency != "size" %} + {{ logrotate_frequency }} +{% else %} + size {{ logrotate_size }} {% endif %} {% if logrotate_notifempty %} notifempty diff --git a/playbooks/roles/mirror-update/tasks/rsync.yaml b/playbooks/roles/mirror-update/tasks/rsync.yaml index 34557d4f07..fbf49e326f 100644 --- a/playbooks/roles/mirror-update/tasks/rsync.yaml +++ b/playbooks/roles/mirror-update/tasks/rsync.yaml @@ -53,4 +53,5 @@ name: logrotate vars: logrotate_file_name: '/var/log/rsync-mirrors/{{ item }}.log' + logrotate_frequency: 'weekly' loop: '{{ rsync_update_scripts }}' \ No newline at end of file