Files
infra-automation/roles/system_info/tasks/main.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

78 lines
2.1 KiB
YAML

---
# tasks file for system_info
- name: Include OS-specific variables
include_vars: "{{ ansible_os_family }}.yml"
ignore_errors: true
tags: [always]
- name: Validate required variables
assert:
that:
- system_info_stats_base_dir is defined
- system_info_stats_base_dir | length > 0
fail_msg: "Required variable 'system_info_stats_base_dir' is not defined or empty"
tags: [validate]
- name: Set statistics directory path
set_fact:
system_info_stats_dir: "{{ system_info_stats_base_dir }}/{{ ansible_fqdn }}"
tags: [always]
- name: Create statistics directory on control node
file:
path: "{{ system_info_stats_dir }}"
state: directory
mode: '0755'
delegate_to: localhost
become: false
when: system_info_create_stats_dir | bool
tags: [install, setup]
- name: Include installation tasks
include_tasks: install.yml
tags: [install]
- name: Include system information gathering tasks
include_tasks: gather_system.yml
when: system_info_gather_system | bool
tags: [gather, system]
- name: Include CPU information gathering tasks
include_tasks: gather_cpu.yml
when: system_info_gather_cpu | bool
tags: [gather, cpu]
- name: Include GPU information gathering tasks
include_tasks: gather_gpu.yml
when: system_info_gather_gpu | bool
tags: [gather, gpu]
- name: Include memory information gathering tasks
include_tasks: gather_memory.yml
when: system_info_gather_memory | bool
tags: [gather, memory]
- name: Include disk information gathering tasks
include_tasks: gather_disk.yml
when: system_info_gather_disk | bool
tags: [gather, disk]
- name: Include network information gathering tasks
include_tasks: gather_network.yml
when: system_info_gather_network | bool
tags: [gather, network]
- name: Include hypervisor detection tasks
include_tasks: detect_hypervisor.yml
when: system_info_detect_hypervisor | bool
tags: [gather, hypervisor]
- name: Include statistics aggregation and export tasks
include_tasks: export_stats.yml
tags: [export, statistics]
- name: Include validation tasks
include_tasks: validate.yml
tags: [validate, health-check]