# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low

- name: Configure daily log rotation in /etc/logrotate.conf
  ansible.builtin.lineinfile:
    create: yes
    dest: "/etc/logrotate.conf"
    regexp: '^\s*(weekly|monthly|yearly)$'
    line: "daily"
    state: present
    insertbefore: BOF

- name: Make sure daily log rotation setting is not overridden in /etc/logrotate.conf
  ansible.builtin.lineinfile:
    create: no
    dest: "/etc/logrotate.conf"
    regexp: '^[\s]*(weekly|monthly|yearly)$'
    state: absent

{{% if 'sle' in product or product == 'slmicro5' %}}
- name: Enable timer logrotate
  ansible.builtin.systemd:
    name: "logrotate.timer"
    enabled: "yes"
    state: "started"
    masked: "no"
{{% else %}}
- name: Configure cron.daily if not already
  block:
    - name: Add shebang
      ansible.builtin.lineinfile:
        path: "/etc/cron.daily/logrotate"
        line: "#!/bin/sh"
        insertbefore: BOF
        create: yes
    - name: Add logrotate call
      ansible.builtin.lineinfile:
        path: "/etc/cron.daily/logrotate"
        line: '/usr/sbin/logrotate /etc/logrotate.conf'
        regexp: '^[\s]*/usr/sbin/logrotate[\s\S]*/etc/logrotate.conf$'
        create: yes
{{% endif %}}
