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>
74 lines
2.7 KiB
YAML
74 lines
2.7 KiB
YAML
---
|
|
# Statistics aggregation and export tasks
|
|
|
|
- name: Set collection timestamp
|
|
set_fact:
|
|
system_info_timestamp: "{{ ansible_date_time.iso8601 }}"
|
|
system_info_timestamp_epoch: "{{ ansible_date_time.epoch }}"
|
|
tags: [export, statistics]
|
|
|
|
- name: Aggregate all system information
|
|
set_fact:
|
|
system_info_complete:
|
|
collection_info:
|
|
timestamp: "{{ system_info_timestamp }}"
|
|
timestamp_epoch: "{{ system_info_timestamp_epoch }}"
|
|
collected_by: "ansible"
|
|
role_version: "{{ system_info_role_version }}"
|
|
ansible_version: "{{ ansible_version.full }}"
|
|
host_info:
|
|
hostname: "{{ system_info_hostname }}"
|
|
fqdn: "{{ system_info_fqdn }}"
|
|
uptime: "{{ system_info_uptime }}"
|
|
boot_time: "{{ system_info_boot_time }}"
|
|
system: "{{ system_info_os | default({}) }}"
|
|
kernel: "{{ system_info_kernel | default({}) }}"
|
|
hardware: "{{ system_info_hardware | default({}) }}"
|
|
security:
|
|
selinux: "{{ system_info_selinux_status | default('N/A') }}"
|
|
apparmor: "{{ system_info_apparmor_status | default('N/A') }}"
|
|
cpu: "{{ system_info_cpu | default({}) }}"
|
|
gpu: "{{ system_info_gpu | default({}) }}"
|
|
memory: "{{ system_info_memory | default({}) }}"
|
|
swap: "{{ system_info_swap | default({}) }}"
|
|
disk: "{{ system_info_disk | default({}) }}"
|
|
network: "{{ system_info_network | default({}) }}"
|
|
hypervisor: "{{ system_info_hypervisor | default({}) }}"
|
|
tags: [export, statistics]
|
|
|
|
- name: Create JSON statistics file on control node
|
|
copy:
|
|
content: "{{ system_info_complete | to_nice_json(indent=system_info_json_indent) }}"
|
|
dest: "{{ system_info_stats_dir }}/system_info.json"
|
|
mode: '0644'
|
|
delegate_to: localhost
|
|
become: false
|
|
tags: [export, statistics]
|
|
|
|
- name: Create timestamped JSON backup
|
|
copy:
|
|
content: "{{ system_info_complete | to_nice_json(indent=system_info_json_indent) }}"
|
|
dest: "{{ system_info_stats_dir }}/system_info_{{ system_info_timestamp_epoch }}.json"
|
|
mode: '0644'
|
|
delegate_to: localhost
|
|
become: false
|
|
tags: [export, statistics, backup]
|
|
|
|
- name: Create human-readable summary file
|
|
template:
|
|
src: summary.txt.j2
|
|
dest: "{{ system_info_stats_dir }}/summary.txt"
|
|
mode: '0644'
|
|
delegate_to: localhost
|
|
become: false
|
|
tags: [export, statistics, summary]
|
|
|
|
- name: Display statistics file location
|
|
debug:
|
|
msg:
|
|
- "System information collected successfully"
|
|
- "Statistics saved to: {{ system_info_stats_dir }}/system_info.json"
|
|
- "Summary saved to: {{ system_info_stats_dir }}/summary.txt"
|
|
- "Timestamped backup: {{ system_info_stats_dir }}/system_info_{{ system_info_timestamp_epoch }}.json"
|
|
tags: [export, statistics]
|