---
- name: Linux validate service | Get service info
  systemd:
    name: "{{ service_name }}"
  register: service_stat

- name: Linux validate service | Fail if the service doesn't exist
  fail:
    msg: "The service {{ service_name }} doesn't exist"
  when: service_stat.status.LoadState == "not-found"

- name: Linux validate service | Fail if the service is not running
  fail:
    msg: "The service {{ service_name }} is not running. Current status is {{ service_stat.status.SubState }}"
  when: service_stat.status.SubState != "running"

- name: Linux validate service | Fail if the service result value is not success
  fail:
    msg: "The service result value is not success. Current result value: {{ service_stat.status.Result }}"
  when: service_stat.status.Result != "success"

- name: Linux validate service | Fail if the service is not enabled
  fail:
    msg: "The service {{ service_name }} is not enabled. Current status is {{ service_stat.status.UnitFileState }}"
  when: service_stat.status.UnitFileState != "enabled"
