Files
infra-automation/roles/system_info/tasks/gather_disk.yml
ansible 70b57d223f Add system_info role for comprehensive infrastructure inventory
New role for gathering detailed system information including CPU, GPU,
RAM, disk, network, and hypervisor details with JSON export capabilities.

Role capabilities:
- Comprehensive hardware detection (CPU, GPU, RAM, disk, network)
- Hypervisor detection (KVM, Proxmox, LXD, Docker, Podman, VMware, Hyper-V)
- System information gathering (OS, kernel, uptime, security modules)
- Health checks and validation tasks
- JSON export with timestamped backups
- Human-readable summary generation
- Support for multiple Linux distributions

Features:
- Modular task organization by information type
- Feature toggles for selective gathering
- CLAUDE.md compliant validation tasks including:
  * Disk usage monitoring (>80% warnings)
  * Memory usage statistics
  * Top CPU and memory processes
  * System uptime tracking
  * Logged users reporting
- OS-specific variable handling
- DMI/SMBIOS hardware information
- SMART disk health status
- Network interface statistics

File structure:
roles/system_info/
├── README.md              # Comprehensive documentation
├── defaults/main.yml      # Configurable defaults
├── vars/main.yml          # Role variables
├── meta/main.yml          # Galaxy metadata
├── tasks/
│   ├── main.yml          # Main task coordinator
│   ├── install.yml       # Package installation
│   ├── gather_system.yml # OS and system info
│   ├── gather_cpu.yml    # CPU details
│   ├── gather_gpu.yml    # GPU detection
│   ├── gather_memory.yml # RAM information
│   ├── gather_disk.yml   # Disk and LVM info
│   ├── gather_network.yml # Network configuration
│   ├── detect_hypervisor.yml # Virtualization detection
│   ├── export_stats.yml  # JSON export
│   └── validate.yml      # Health checks (CLAUDE.md compliant)
├── templates/
│   └── summary.txt.j2    # Human-readable summary
├── handlers/
│   └── main.yml          # Service handlers
└── tests/
    └── test.yml          # Basic test playbook

Use cases:
- Infrastructure inventory for CMDB integration
- Capacity planning and resource optimization
- Hardware audit and compliance reporting
- Hypervisor and VM tracking
- System health monitoring
- Documentation generation

Output:
- JSON: ./stats/machines/<fqdn>/system_info.json
- Backup: ./stats/machines/<fqdn>/system_info_<timestamp>.json
- Summary: ./stats/machines/<fqdn>/summary.txt

Requirements:
- Ansible >= 2.9
- Root/sudo access for hardware information
- Packages: lshw, dmidecode, pciutils, usbutils, smartmontools, ethtool

Compliance:
- CLAUDE.md health check requirements implemented
- CIS Benchmark support for system auditing
- NIST compliance documentation support
- Security-first design with minimal system impact

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-11 01:36:01 +01:00

140 lines
4.2 KiB
YAML

---
# Disk information gathering tasks
- name: Gather disk usage information
shell: df -h | grep -vE '^Filesystem|tmpfs|cdrom'
register: system_info_disk_usage_raw
changed_when: false
failed_when: false
tags: [gather, disk]
- name: Gather disk usage in machine-readable format
shell: df -B1 | grep -vE '^Filesystem|tmpfs|cdrom'
register: system_info_disk_usage_bytes_raw
changed_when: false
failed_when: false
tags: [gather, disk]
- name: List block devices
shell: lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,FSTYPE,MODEL,SERIAL
register: system_info_lsblk_raw
changed_when: false
tags: [gather, disk]
- name: Gather detailed block device information
shell: lsblk -J -o NAME,SIZE,TYPE,MOUNTPOINT,FSTYPE,UUID,PARTUUID,MODEL,SERIAL,STATE,ROTA
register: system_info_lsblk_json_raw
changed_when: false
tags: [gather, disk]
- name: Check for LVM usage
shell: |
if command -v pvs &> /dev/null; then
echo "=== Physical Volumes ==="
pvs
echo "=== Volume Groups ==="
vgs
echo "=== Logical Volumes ==="
lvs
else
echo "LVM not configured or not available"
fi
register: system_info_lvm_raw
changed_when: false
become: true
failed_when: false
tags: [gather, disk]
- name: Detect if LVM is in use
set_fact:
system_info_lvm_detected: "{{ 'Physical Volumes' in system_info_lvm_raw.stdout }}"
tags: [gather, disk]
- name: Gather mount points information
shell: mount | grep -vE "tmpfs|devtmpfs|sysfs|proc|cgroup"
register: system_info_mounts_raw
changed_when: false
failed_when: false
tags: [gather, disk]
- name: Check for RAID arrays
shell: |
if [ -f /proc/mdstat ]; then
cat /proc/mdstat
else
echo "No software RAID detected"
fi
register: system_info_mdstat_raw
changed_when: false
tags: [gather, disk]
- name: Detect hardware RAID controllers
shell: lspci | grep -iE "raid|storage controller" || echo "No hardware RAID controllers detected"
register: system_info_hw_raid_raw
changed_when: false
tags: [gather, disk]
- name: Gather disk I/O statistics
shell: iostat -x 1 2 | tail -n +4
register: system_info_iostat_raw
changed_when: false
failed_when: false
tags: [gather, disk]
- name: List physical disks
shell: lsblk -d -o NAME,SIZE,TYPE,ROTA,MODEL | grep disk
register: system_info_physical_disks_raw
changed_when: false
tags: [gather, disk]
- name: Check for SSD vs HDD
shell: |
for disk in $(lsblk -d -n -o NAME,TYPE | grep disk | awk '{print $1}'); do
rota=$(cat /sys/block/$disk/queue/rotational 2>/dev/null || echo "unknown")
if [ "$rota" = "0" ]; then
echo "$disk: SSD"
elif [ "$rota" = "1" ]; then
echo "$disk: HDD"
else
echo "$disk: Unknown"
fi
done
register: system_info_disk_types_raw
changed_when: false
failed_when: false
tags: [gather, disk]
- name: Gather SMART status (if available)
shell: |
if command -v smartctl &> /dev/null; then
for disk in $(lsblk -d -n -o NAME,TYPE | grep disk | awk '{print $1}'); do
echo "=== /dev/$disk ==="
smartctl -H /dev/$disk 2>/dev/null || echo "SMART not available for /dev/$disk"
done
else
echo "smartctl not available"
fi
register: system_info_smart_raw
changed_when: false
become: true
failed_when: false
tags: [gather, disk]
- name: Aggregate disk information
set_fact:
system_info_disk:
usage_human: "{{ system_info_disk_usage_raw.stdout_lines | default([]) }}"
block_devices: "{{ system_info_lsblk_raw.stdout_lines }}"
lvm:
enabled: "{{ system_info_lvm_detected }}"
details: "{{ system_info_lvm_raw.stdout_lines | default([]) }}"
mounts: "{{ system_info_mounts_raw.stdout_lines | default([]) }}"
raid:
software: "{{ system_info_mdstat_raw.stdout_lines }}"
hardware: "{{ system_info_hw_raid_raw.stdout_lines }}"
physical_disks: "{{ system_info_physical_disks_raw.stdout_lines | default([]) }}"
disk_types: "{{ system_info_disk_types_raw.stdout_lines | default([]) }}"
smart_status: "{{ system_info_smart_raw.stdout_lines | default([]) }}"
io_stats: "{{ system_info_iostat_raw.stdout_lines | default([]) }}"
tags: [gather, disk]