testing new proxmox logic
This commit is contained in:
127
roles/proxmox_status/tasks/main.yml
Normal file
127
roles/proxmox_status/tasks/main.yml
Normal file
@@ -0,0 +1,127 @@
|
||||
---
|
||||
# =============================================================================
|
||||
# proxmox_status — tasks
|
||||
# Produces a cluster health report: nodes, VMs, storage, CEPH, HA.
|
||||
# =============================================================================
|
||||
|
||||
# ── Node info ─────────────────────────────────────────────────────────────────
|
||||
- name: "Status | Get cluster node info"
|
||||
community.proxmox.proxmox_node_info:
|
||||
api_host: "{{ api_host }}"
|
||||
api_user: "{{ api_user }}"
|
||||
api_token_id: "{{ api_token_id }}"
|
||||
api_token_secret: "{{ api_token_secret }}"
|
||||
api_port: "{{ api_port }}"
|
||||
validate_certs: "{{ validate_certs }}"
|
||||
register: status_nodes
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
|
||||
- name: "Status | Node summary"
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
┌─ NODE SUMMARY ─────────────────────────────
|
||||
{% for node in status_nodes.proxmox_nodes | sort(attribute='node') %}
|
||||
│ {{ node.node | ljust(20) }}
|
||||
status={{ node.status | ljust(8) }}
|
||||
ver={{ node.version.version | default('?') }}
|
||||
cpu={{ (node.cpu | default(0) * 100) | round(1) }}%
|
||||
mem={{ ((node.mem | default(0)) / 1073741824) | round(1) }}GB /
|
||||
{{ ((node.maxmem | default(0)) / 1073741824) | round(1) }}GB
|
||||
{% endfor %}
|
||||
└────────────────────────────────────────────
|
||||
run_once: true
|
||||
|
||||
# ── VM inventory ──────────────────────────────────────────────────────────────
|
||||
- name: "Status | Get VM info for each node"
|
||||
community.proxmox.proxmox_vm_info:
|
||||
api_host: "{{ api_host }}"
|
||||
api_user: "{{ api_user }}"
|
||||
api_token_id: "{{ api_token_id }}"
|
||||
api_token_secret: "{{ api_token_secret }}"
|
||||
api_port: "{{ api_port }}"
|
||||
validate_certs: "{{ validate_certs }}"
|
||||
node: "{{ item.node }}"
|
||||
loop: "{{ status_nodes.proxmox_nodes | selectattr('status', 'equalto', 'online') | list }}"
|
||||
loop_control:
|
||||
label: "{{ item.node }}"
|
||||
register: status_vms_per_node
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
when: status_include_vms
|
||||
|
||||
- name: "Status | VM distribution summary"
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
┌─ VM DISTRIBUTION ──────────────────────────
|
||||
{% for result in status_vms_per_node.results %}
|
||||
│ {{ result.item.node | ljust(20) }}
|
||||
total={{ result.proxmox_vms | length }}
|
||||
running={{ result.proxmox_vms | selectattr('status', 'equalto', 'running') | list | length }}
|
||||
stopped={{ result.proxmox_vms | selectattr('status', 'equalto', 'stopped') | list | length }}
|
||||
{% endfor %}
|
||||
│ Total VMs: {{ status_vms_per_node.results | map(attribute='proxmox_vms') | flatten | length }}
|
||||
└────────────────────────────────────────────
|
||||
run_once: true
|
||||
when: status_include_vms
|
||||
|
||||
# ── CEPH status ───────────────────────────────────────────────────────────────
|
||||
- name: "Status | CEPH status"
|
||||
ansible.builtin.command: ceph status --format json
|
||||
register: status_ceph
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
run_once: true
|
||||
when: status_include_ceph
|
||||
|
||||
- name: "Status | CEPH summary"
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
┌─ CEPH STATUS ───────────────────────────────
|
||||
{% if status_ceph.rc == 0 %}
|
||||
│ Health: {{ (status_ceph.stdout | from_json).health.status }}
|
||||
│ OSDs: {{ (status_ceph.stdout | from_json).osdmap.num_osds }} total,
|
||||
{{ (status_ceph.stdout | from_json).osdmap.num_up_osds }} up,
|
||||
{{ (status_ceph.stdout | from_json).osdmap.num_in_osds }} in
|
||||
{% else %}
|
||||
│ CEPH not configured or not reachable.
|
||||
{% endif %}
|
||||
└────────────────────────────────────────────
|
||||
run_once: true
|
||||
when: status_include_ceph
|
||||
|
||||
# ── HA status ─────────────────────────────────────────────────────────────────
|
||||
- name: "Status | HA status"
|
||||
ansible.builtin.command: ha-manager status
|
||||
register: status_ha
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
run_once: true
|
||||
when: status_include_ha
|
||||
|
||||
- name: "Status | HA summary"
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
┌─ HA STATUS ─────────────────────────────────
|
||||
{% if status_ha.rc == 0 and status_ha.stdout != '' %}
|
||||
{{ status_ha.stdout_lines | join('\n ') }}
|
||||
{% else %}
|
||||
│ HA not configured.
|
||||
{% endif %}
|
||||
└────────────────────────────────────────────
|
||||
run_once: true
|
||||
when: status_include_ha
|
||||
|
||||
# ── PVE versions ─────────────────────────────────────────────────────────────
|
||||
- name: "Status | Check for available updates on each node"
|
||||
ansible.builtin.shell: |
|
||||
apt-get -q update > /dev/null 2>&1
|
||||
apt-get -s dist-upgrade 2>/dev/null | grep "^Inst " | wc -l
|
||||
register: status_updates_available
|
||||
changed_when: false
|
||||
|
||||
- name: "Status | Update availability per node"
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
{{ inventory_hostname }}: {{ status_updates_available.stdout | trim }} package(s) available for upgrade
|
||||
(PVE {{ ansible_local.pve_version | default('unknown') }})
|
||||
Reference in New Issue
Block a user