Execution
Date 16 Sep 2025 09:30:28 +0100
Duration 00:00:44.23
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
44 Hosts
6 Tasks
233 Results
44 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/RM10132_kvm_restart_required.yaml

---
- name: Process KVM Hosts That Require Restart
  hosts: all
  gather_facts: false

  tasks:
    - name: Check if system needs restarting
      kvm_upgrade_utils:
        action: check_restart
      register: restart_status
      changed_when: restart_status.needs_restarting

    - name: Display restart requirement status
      ansible.builtin.debug:
        msg: |
          Host: {{ inventory_hostname }}
          {% if restart_status.needs_restarting %}
          🚨 RESTART REQUIRED
          {% else %}
          ✅ No restart needed
          {% endif %}
      changed_when: restart_status.needs_restarting

    - name: Set fact for hosts requiring restart
      ansible.builtin.set_fact:
        host_needs_restart: "{{ restart_status.needs_restarting }}"
      delegate_to: localhost
      delegate_facts: true
      run_once: true

- name: Process hosts that need restart
  hosts: all
  gather_facts: false
  serial: 1

  tasks:
    - name: Check if this host needs restart
      ansible.builtin.debug:
        msg: "Checking restart status for {{ inventory_hostname }}"
      delegate_to: localhost
      run_once: true

    - name: Perform restart actions for hosts that need it
      ansible.builtin.debug:
        msg: |
          ========================================
          Processing restart for: {{ inventory_hostname }}
          ========================================
          🚨 RESTART ACTIONS REQUIRED:
          1. Schedule maintenance window
          2. Migrate VMs if possible
          3. Notify customers
          4. Reboot host
          5. Verify services after restart
          ========================================
      when: hostvars[inventory_hostname]['restart_status']['needs_restarting'] | default(false)
      changed_when: true

    - name: Skip hosts that don't need restart
      ansible.builtin.debug:
        msg: "✅ {{ inventory_hostname }}: No restart required, skipping..."
      when: not (hostvars[inventory_hostname]['restart_status']['needs_restarting'] | default(false))