---
- name: Configure logrotate
  tags: [nginx, nginx_conf, nginx_logrotate]
  block:
    - name: Manage the log rotate size
      ansible.builtin.lineinfile:
        path: /etc/logrotate.d/nginx
        insertbefore: notifempty
        unsafe_writes: false
        create: false
        state: present
        firstmatch: true
        regexp: maxsize.*$
        line: "        maxsize {{ nginx_logrotate_maxfilesize }}"

    - name: Manage the log rotate size
      ansible.builtin.lineinfile:
        path: /etc/logrotate.d/nginx
        insertbefore: notifempty
        unsafe_writes: false
        create: false
        state: present
        firstmatch: true
        regexp: rotate.*$
        line: "        rotate {{ nginx_logrotate_retention }}"
