Testing

# File: roles/generate_aap_report/tasks/main.yml
---
- name: Gather date/time facts
  ansible.builtin.setup:
    filter: ansible_date_time

- name: Normalise all lists from extra vars (safe defaults)
  ansible.builtin.set_fact:
    db_list:         "{{ db_status_list      | default([]) }}"
    servers:         "{{ server_status_list  | default([]) }}"
    gateways:        "{{ gateway_list        | default([]) }}"
    eda_list:        "{{ eda_list            | default([]) }}"
    certs:           "{{ cert_status_list    | default([]) }}"
    topology:        "{{ topology_status_list| default([]) }}"
    demo_jobs:       "{{ demo_job_output     | default([]) }}"

- name: Generate full HTML report – now includes Demo Jobs
  ansible.builtin.set_fact:
    aap_html_report: |
      <!DOCTYPE html>
      <html>
      <head>
        <meta charset="UTF-8">
        <title>AAP Cluster Health Report – {{ ansible_date_time.date }}</title>
        <style>
          body {font-family: Calibri, Arial, sans-serif; background:#f9f9f9; padding:20px; color:#333;}
          h1 {color:#1a5276; text-align:center;}
          h2 {color:#2e86c1; border-bottom:2px solid #2e86c1; padding-bottom:8px; margin-top:45px;}
          table {width:100%; max-width:1100px; margin:20px auto; border-collapse:collapse; background:white; box-shadow:0 4px 15px rgba(0,0,0,0.1);}
          th, td {padding:12px 16px; text-align:left; border:1px solid #ddd;}
          th {background:#1a5276; color:white;}
          tr:nth-child(even) {background:#f8f9fa;}
          .ok     {background:#d5f5e3 !important; color:#27ae60; font-weight:bold;}
          .failed {background:#fadbd8 !important; color:#c0392b; font-weight:bold;}
          a {color:#1a5276; text-decoration:none;}
          a:hover {text-decoration:underline;}
          .footer {margin-top:80px; text-align:center; color:#7f8c8d; font-size:0.9em;}
        </style>
      </head>
      <body>

      <h1>Ansible Automation Platform – Cluster Health Report</h1>
      <p style="text-align:center;">
        <strong>Generated:</strong> {{ ansible_date_time.iso8601 }}<br>
        Controller: {{ inventory_hostname }}
      </p>

      {% if db_list | length > 0 %}
      <h2>PostgreSQL Database Status</h2>
      <table>
        <tr><th>DB URL</th><th>Status</th><th>Health</th></tr>
        {% for d in db_list %}
        <tr>
          <td>{{ d.DB_URL }}</td>
          <td>{{ d.DB_Status }}</td>
          <td class="{% if d.healthy %}ok{% else %}failed{% endif %}">
            {% if d.healthy %}OK{% else %}FAILED{% endif %}
          </td>
        </tr>
        {% endfor %}
      </table>
      {% endif %}

      {% if servers | length > 0 %}
      <h2>Controller / Hybrid Nodes</h2>
      <table>
        <tr><th>Node</th><th>Status</th><th>Type</th><th>Health</th></tr>
        {% for n in servers %}
        <tr>
          <td>{{ n.node }}</td>
          <td>{{ n.status }}</td>
          <td>{{ n.node_type | default('hybrid') }}</td>
          <td class="{% if n.healthy %}ok{% else %}failed{% endif %}">
            {% if n.healthy %}OK{% else %}FAILED{% endif %}
          </td>
        </tr>
        {% endfor %}
      </table>
      {% endif %}

      {% if gateways | length > 0 %}
      <h2>Automation Gateway Nodes</h2>
      <table>
        <tr><th>Node</th><th>Status</th><th>Health</th></tr>
        {% for g in gateways %}
        <tr>
          <td>{{ g.node }}</td>
          <td>{{ g.status }}</td>
          <td class="{% if g.healthy %}ok{% else %}failed{% endif %}">
            {% if g.healthy %}OK{% else %}FAILED{% endif %}
          </td>
        </tr>
        {% endfor %}
      </table>
      {% endif %}

      {% if eda_list | length > 0 %}
      <h2>Event-Driven Ansible (EDA) Controllers</h2>
      <table>
        <tr><th>EDA URL</th><th>Status</th><th>Health</th></tr>
        {% for e in eda_list %}
        {% set eda_healthy = e.healthy or (e.status | lower == 'good') %}
        <tr>
          <td>
            <a href="{{ e.url }}">
              {{ e.url | regex_replace('^https?://', '') | regex_replace(':443.*', '') | regex_replace('/api/eda/v1/status/$', '') }}
            </a>
          </td>
          <td>{{ e.status }}</td>
          <td class="{% if eda_healthy %}ok{% else %}failed{% endif %}">
            {% if eda_healthy %}OK{% else %}FAILED{% endif %}
          </td>
        </tr>
        {% endfor %}
      </table>
      {% endif %}

      {% if demo_jobs | length > 0 %}
      <h2>Demo Jobs Status</h2>
      <table>
        <tr><th>Job Name</th><th>Status</th><th>Health</th></tr>
        {% for j in demo_jobs %}
        <tr>
          <td>{{ j.job_name }}</td>
          <td>{{ j.status }}</td>
          <td class="{% if j.healthy %}ok{% else %}failed{% endif %}">
            {% if j.healthy %}OK{% else %}FAILED{% endif %}
          </td>
        </tr>
        {% endfor %}
      </table>
      {% endif %}

      {% if certs | length > 0 %}
      <h2>SSL Certificate Expiry</h2>
      <table>
        <tr><th>Node</th><th>Days Left</th><th>Health</th></tr>
        {% for c in certs %}
        <tr>
          <td>{{ c.node }}</td>
          <td>{{ c.cert_expiry_days_left }}</td>
          <td class="{% if c.healthy %}ok{% else %}failed{% endif %}">
            {% if c.healthy %}OK{% else %}FAILED{% endif %}
          </td>
        </tr>
        {% endfor %}
      </table>
      {% endif %}

      {% if topology | length > 0 %}
      <h2>Receptor Mesh Topology</h2>
      <table>
        <tr><th>Source → Target</th><th>Link State</th><th>Health</th></tr>
        {% for t in topology %}
        <tr>
          <td>{{ t.source }} → {{ t.target }}</td>
          <td>{{ t.link_state }}</td>
          <td class="{% if t.healthy %}ok{% else %}failed{% endif %}">
            {% if t.healthy %}OK{% else %}FAILED{% endif %}
          </td>
        </tr>
        {% endfor %}
      </table>
      {% endif %}

      <div class="footer">
        Report auto-generated by Ansible Automation Platform<br>
        {{ ansible_date_time.iso8601 }}
      </div>
      </body>
      </html>

Comments

Popular posts from this blog

HP-UX virtual Machine Cheat Sheet

Install Perl DBD::Oracle Module