Execution
Date 18 Mar 2024 12:13:48 +0000
Duration 00:00:10.54
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.4
ara 1.7.1 / 1.7.2.dev2
Python 3.10.10
Summary
16 Hosts
4 Tasks
64 Results
1 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/check-kcare.yaml

---
- name: Check if kcare.service is present and running, restart if not active
  hosts: all
  gather_facts: true

  tasks:
    - name: Check if kcare.service exists
      stat:
        path: /etc/systemd/system/kcare.service
      register: kcare_service

    - name: Check if kcare.service is running
      command: systemctl is-active kcare.service
      register: kcare_service_status
      ignore_errors: true

    - name: Restart kcare.service if not active
      systemd:
        name: kcare.service
        state: restarted
      when: kcare_service.stat.exists and kcare_service_status.stdout != "active"

    - name: Display status message
      debug:
        msg: |
          kcare.service status:
          Exists: {{ kcare_service.stat.exists | default(false) }}
          Running: {{ kcare_service_status.stdout | default('Unknown') }}