# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low
- name: Check that the systemd-journal group is defined
  ansible.builtin.getent:
    database: group
    key: systemd-journal
  ignore_errors: yes
  when: file_groupowner_system_journal_newgroup is undefined

- name: Set the file_groupowner_system_journal_newgroup variable if systemd-journal found
  ansible.builtin.set_fact:
    file_groupowner_system_journal_newgroup: "systemd-journal"
  when: ansible_facts.getent_group["systemd-journal"] is defined

- name: Find /run/log/journal/ file(s) matching ^.*$ recursively
  ansible.builtin.command: 'find -P /run/log/journal/  -type f  ! -group systemd-journal -regextype posix-extended -regex "^.*$"'
  register: files_found
  changed_when: False
  failed_when: False
  check_mode: no

- name: Ensure group owner on /run/log/journal/ file(s) matching ^.*$
  ansible.builtin.file:
    path: "{{ item }}"
    follow: false
    group: "{{ file_groupowner_system_journal_newgroup }}"
    state: file
  with_items:
    - "{{ files_found.stdout_lines }}"





- name: Find /var/log/journal/ file(s) matching ^.*$ recursively
  ansible.builtin.command: 'find -P /var/log/journal/  -type f  ! -group systemd-journal -regextype posix-extended -regex "^.*$"'
  register: files_found
  changed_when: False
  failed_when: False
  check_mode: no

- name: Ensure group owner on /var/log/journal/ file(s) matching ^.*$
  ansible.builtin.file:
    path: "{{ item }}"
    follow: false
    group: "{{ file_groupowner_system_journal_newgroup }}"
    state: file
  with_items:
    - "{{ files_found.stdout_lines }}"



