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

92 lines
3.1 KiB
YAML

---
# System information gathering tasks
- name: Gather system information - Hostname
set_fact:
system_info_hostname: "{{ ansible_hostname }}"
system_info_fqdn: "{{ ansible_fqdn }}"
tags: [gather, system]
- name: Gather system information - OS details
set_fact:
system_info_os:
distribution: "{{ ansible_distribution }}"
distribution_version: "{{ ansible_distribution_version }}"
distribution_release: "{{ ansible_distribution_release }}"
distribution_major_version: "{{ ansible_distribution_major_version }}"
os_family: "{{ ansible_os_family }}"
tags: [gather, system]
- name: Gather system information - Kernel
set_fact:
system_info_kernel:
version: "{{ ansible_kernel }}"
architecture: "{{ ansible_architecture }}"
tags: [gather, system]
- name: Gather system uptime
shell: uptime -p
register: system_info_uptime_raw
changed_when: false
failed_when: false
tags: [gather, system]
- name: Gather system boot time
shell: uptime -s
register: system_info_boot_time_raw
changed_when: false
failed_when: false
tags: [gather, system]
- name: Set uptime facts
set_fact:
system_info_uptime: "{{ system_info_uptime_raw.stdout | default('Unknown') }}"
system_info_boot_time: "{{ system_info_boot_time_raw.stdout | default('Unknown') }}"
tags: [gather, system]
- name: Gather DMI/SMBIOS information
shell: dmidecode -t system | grep -E "Manufacturer|Product Name|Serial Number|UUID" || echo "Not available"
register: system_info_dmi_raw
changed_when: false
become: true
failed_when: false
tags: [gather, system]
- name: Parse DMI information
set_fact:
system_info_hardware:
manufacturer: "{{ system_info_dmi_raw.stdout | regex_search('Manufacturer: (.+)', '\\1') | default(['Unknown'], true) | first }}"
product: "{{ system_info_dmi_raw.stdout | regex_search('Product Name: (.+)', '\\1') | default(['Unknown'], true) | first }}"
serial: "{{ system_info_dmi_raw.stdout | regex_search('Serial Number: (.+)', '\\1') | default(['Unknown'], true) | first }}"
uuid: "{{ system_info_dmi_raw.stdout | regex_search('UUID: (.+)', '\\1') | default(['Unknown'], true) | first }}"
tags: [gather, system]
- name: Gather SELinux status (RHEL-based)
shell: getenforce
register: system_info_selinux_raw
changed_when: false
failed_when: false
when: ansible_os_family == "RedHat"
tags: [gather, system, security]
- name: Set SELinux status
set_fact:
system_info_selinux_status: "{{ system_info_selinux_raw.stdout | default('Not applicable') }}"
when: ansible_os_family == "RedHat"
tags: [gather, system, security]
- name: Gather AppArmor status (Debian-based)
shell: aa-status --enabled && echo "Enabled" || echo "Disabled"
register: system_info_apparmor_raw
changed_when: false
failed_when: false
become: true
when: ansible_os_family == "Debian"
tags: [gather, system, security]
- name: Set AppArmor status
set_fact:
system_info_apparmor_status: "{{ system_info_apparmor_raw.stdout | default('Not applicable') }}"
when: ansible_os_family == "Debian"
tags: [gather, system, security]