---
- name: remove rotated logs from remote machines
  hosts: all
  ignore_unreachable: yes
  max_fail_percentage: 5
  tasks:
    - name: remove rotated logs
      shell: |
        for file in $(find /var/log/safenode/ -name "*.gz"); do
          rm $file
        done

    - name: setup cron job to remove rotated logs every 10 minutes
      ansible.builtin.cron:
        name: "cleanup_logs"
        minute: "*/10"
        job: "find /var/log/safenode/ -name \"*.gz\" -exec rm {} \\;"
        state: present
      when: setup_cron == "true"