Execution
Date 15 Sep 2025 16:01:34 +0100
Duration 00:00:25.63
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.11
ara 1.7.3 / 1.7.3
Python 3.10.10
Summary
43 Hosts
4 Tasks
157 Results
1 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/zz-needs-restarting.yaml

---
- name: Check if server needs restarting
  hosts: all
  gather_facts: false

  tasks:
    - name: Check if system needs restarting (RHEL/CentOS)
      ansible.builtin.command: needs-restarting -r
      register: restart_check
      ignore_errors: true
      changed_when: false

    - name: Evaluate restart status
      ansible.builtin.set_fact:
        needs_restarting: "{{ restart_check.rc != 0 }}"

    - name: Display restart status
      ansible.builtin.debug:
        msg: |
          {% if needs_restarting %}
          ⚠️  Server REQUIRES a restart
          Reason: {{ restart_check.stderr_lines | join(', ') }}
          {% else %}
          ✅ Server does NOT need a restart
          {% endif %}

    - name: Show detailed restart information
      ansible.builtin.debug:
        var: restart_check
      when: needs_restarting