# SPDX-License-Identifier: MIT
---
- name: Set platform/version specific variables
  include_tasks: tasks/set_vars.yml

- name: Warn if journald_sync_interval is set in volatile mode
  debug:
    msg: >-
      WARNING - journald_sync_interval should not be set when
      journald_persistent: false
  when:
    - journald_sync_interval | int != 0
    - not journald_persistent

- name: Ensure required packages are installed
  package:
    name: "{{ __journald_packages }}"
    state: present
    use: "{{ (__journald_is_ostree | d(false)) | ternary('ansible.posix.rhel_rpm_ostree', omit) }}"

- name: Ensure required services are enabled
  service:
    name: "{{ item }}"
    state: started
    enabled: true
  loop: "{{ __journald_services }}"

- name: Create journald configuration drop-in directory
  file:
    path: "{{ __journald_dropin_dir }}"
    state: directory
    owner: root
    group: root
    mode: '0755'

- name: Configure persistent journal
  include_tasks: tasks/persistent.yml
  when: journald_persistent | bool

- name: Configure volatile journal
  include_tasks: tasks/volatile.yml
  when: not (journald_persistent | bool)

- name: Deploy journald configuration drop-in
  template:
    src: journald.conf.j2
    dest: "{{ __journald_dropin_dir }}/{{ __journald_dropin_conf }}"
    owner: root
    group: root
    mode: '0644'
  notify:
    - Restart journald services
