# SPDX-License-Identifier: MIT
---
- name: Determine if system is booted with systemd
  block:
    - name: Run systemctl
      # noqa command-instead-of-module
      command:
        cmd: systemctl is-system-running
      register: __test_is_system_running
      changed_when: false
      failed_when: false
      check_mode: false

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

    - name: Skip test if system is not booted
      meta: end_host
      # see https://www.man7.org/linux/man-pages/man1/systemctl.1.html#:~:text=is-system-running%20output
      when: __test_is_system_running.stdout == 'offline'
