---
- name: Clean activity_tracking logs
  block:
    - name: Find logs older than 30 days
      ansible.builtin.find:
        age: 30d
        paths: /apps/octopus/logs/activity_tracking
        recurse: true
      register: logs_to_remove
    - name: Remove logs
      ansible.builtin.file:
        path: "{{ item.path }}"
        state: absent
      with_items: "{{ logs_to_remove.files }}"

- name: Clean generate_batch_reports logs
  block:
    - name: Find logs older than 30 days
      ansible.builtin.find:
        age: 30d
        paths: /apps/octopus/logs/generate_batch_reports
        recurse: true
      register: logs_to_remove
    - name: Remove logs
      ansible.builtin.file:
        path: "{{ item.path }}"
        state: absent
      with_items: "{{ logs_to_remove.files }}"

- name: Clean post-install logs
  block:
    - name: Find logs older than 30 days
      ansible.builtin.find:
        age: 30d
        paths: /apps/octopus/logs/post-install
        recurse: true
      register: logs_to_remove
    - name: Remove logs
      ansible.builtin.file:
        path: "{{ item.path }}"
        state: absent
      with_items: "{{ logs_to_remove.files }}"
