Execution
Date 15 Sep 2025 18:19:03 +0100
Duration 00:00:46.44
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
10 Tasks
377 Results
1 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/zz-kvm_patching_workflow.yml

---
- name: Conditional KVM Host Health Check
  hosts: all
  gather_facts: false
  vars:
    health_check_file: "./zz-kvm_patching_workflow.txt"

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

    - name: Check for available updates
      kvm_upgrade_utils:
        action: check_updates
      register: update_status
      changed_when: update_status.updates_available

    - name: Validate system resources
      kvm_upgrade_utils:
        action: validate_resources
        min_available_ram_mb: 2048
      register: resource_status
      changed_when: not resource_status.resource_status.sufficient_memory

    - name: Check RPM database integrity
      kvm_upgrade_utils:
        action: check_rpm_database
      register: rpm_status
      changed_when: not rpm_status.rpm_database_healthy

    - name: Create header for host status
      ansible.builtin.lineinfile:
        path: "{{ health_check_file }}"
        line: |
          ========================================
          Host: {{ inventory_hostname }}
          ========================================
        create: true
        insertafter: EOF
      delegate_to: localhost

    - name: Add restart status
      ansible.builtin.lineinfile:
        path: "{{ health_check_file }}"
        line: |
          {% if restart_status.needs_restarting %}
          🚨 RESTART REQUIRED
          {% else %}
          ✅ No restart needed
          {% endif %}
        insertafter: EOF
      delegate_to: localhost

    - name: Add updates status
      ansible.builtin.lineinfile:
        path: "{{ health_check_file }}"
        line: |
          {% if update_status.updates_available %}
          📦 Updates: {{ update_status.update_count }} available
          {% else %}
          ✅ No updates available
          {% endif %}
        insertafter: EOF
      delegate_to: localhost

    - name: Add memory status
      ansible.builtin.lineinfile:
        path: "{{ health_check_file }}"
        line: |
          {% if resource_status.resource_status.sufficient_memory %}
          ✅ Memory: {{ resource_status.resource_status.available_ram_mb }}MB available
          {% else %}
          🚨 Memory: LOW ({{ resource_status.resource_status.available_ram_mb }}MB < 2048MB)
          {% endif %}
        insertafter: EOF
      delegate_to: localhost

    - name: Add RPM database status
      ansible.builtin.lineinfile:
        path: "{{ health_check_file }}"
        line: |
          {% if rpm_status.rpm_database_healthy %}
          ✅ RPM Database: Healthy
          {% else %}
          🚨 RPM Database: CORRUPTED
          {% endif %}
        insertafter: EOF
      delegate_to: localhost

    - name: Add footer and empty line
      ansible.builtin.lineinfile:
        path: "{{ health_check_file }}"
        line: |
          ========================================
          
        insertafter: EOF
      delegate_to: localhost