---
# SPDX-License-Identifier: GPL-3.0-only

- name: Determine if system is booted with systemd
  when: __logging_is_booted is not defined
  block:
    - name: Run systemctl
    # noqa command-instead-of-module
      command: systemctl is-system-running
      register: __is_system_running
      changed_when: false
      failed_when: false

    - name: Require installed systemd
      fail:
        msg: "Error: This role requires systemd to be installed."
      when: '"No such file or directory" in __is_system_running.msg | d("")'

    - name: Set flag to indicate that systemd runtime operations are available
      set_fact:
      # see https://www.man7.org/linux/man-pages/man1/systemctl.1.html#:~:text=is-system-running%20output
        __logging_is_booted: "{{ __is_system_running.stdout != 'offline' }}"
