# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low
- name: Gather the package facts
  package_facts:
    manager: auto
  tags:
  - DISA-STIG-UBTU-22-232085
  - configure_strategy
  - dir_groupowner_system_journal
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Check that the systemd-journal group is defined
  ansible.builtin.getent:
    database: group
    key: systemd-journal
  ignore_errors: true
  when:
  - '"linux-base" in ansible_facts.packages'
  - dir_groupowner_system_journal_newgroup is undefined
  tags:
  - DISA-STIG-UBTU-22-232085
  - configure_strategy
  - dir_groupowner_system_journal
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set the dir_groupowner_system_journal_newgroup variable if systemd-journal
    found
  ansible.builtin.set_fact:
    dir_groupowner_system_journal_newgroup: systemd-journal
  when:
  - '"linux-base" in ansible_facts.packages'
  - ansible_facts.getent_group["systemd-journal"] is defined
  tags:
  - DISA-STIG-UBTU-22-232085
  - configure_strategy
  - dir_groupowner_system_journal
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Ensure group owner on /run/log/journal/ recursively
  ansible.builtin.file:
    path: /run/log/journal/
    follow: false
    state: directory
    recurse: true
    group: '{{ dir_groupowner_system_journal_newgroup }}'
  when: '"linux-base" in ansible_facts.packages'
  tags:
  - DISA-STIG-UBTU-22-232085
  - configure_strategy
  - dir_groupowner_system_journal
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Ensure group owner on /var/log/journal/ recursively
  ansible.builtin.file:
    path: /var/log/journal/
    follow: false
    state: directory
    recurse: true
    group: '{{ dir_groupowner_system_journal_newgroup }}'
  when: '"linux-base" in ansible_facts.packages'
  tags:
  - DISA-STIG-UBTU-22-232085
  - configure_strategy
  - dir_groupowner_system_journal
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
