# ansible / monitoring / diagnostics
Automate Server Health Checks in seconds
A purely diagnostic playbook that instantly pulls vitals—CPU, RAM, Disk space, and Load averages—across your entire fleet and prints them directly to your console, without having to SSH into a single box.
Why this playbook holds up
When an alert fires or a user reports slowness, you need answers immediately. Instead of opening 10 terminal tabs, this playbook acts as a distributed stethoscope, registering raw bash outputs and cleanly presenting them in the Ansible debug log.
Strictly Safe Execution
Every single task is a read-only command. It makes zero state changes to the remote hosts, making it 100% safe to run blindly during an active incident.
Familiar Outputs
By leveraging standard Linux commands like free -h and df -h, the debug outputs match exactly what a sysadmin is already used to reading.
The full task list
--- - name: Check server resource usage hosts: all become: yes tasks: - name: Check hostname command: hostname register: hostname - name: Display hostname debug: var: hostname.stdout - name: Check RAM usage command: free -h register: memory - name: Display RAM usage debug: var: memory.stdout_lines - name: Check CPU usage command: top -bn1 register: cpu - name: Display CPU usage debug: var: cpu.stdout_lines - name: Check disk usage command: df -h register: disk - name: Display disk usage debug: var: disk.stdout_lines - name: Check system uptime command: uptime register: uptime - name: Display uptime debug: var: uptime.stdout - name: Check load average shell: cat /proc/loadavg register: load - name: Display load average debug: var: load.stdout - name: Check logged-in users command: who register: users - name: Display logged-in users debug: var: users.stdout_lines - name: Check disk inode usage command: df -i register: inode - name: Display inode usage debug: var: inode.stdout_lines - name: Check mounted file systems command: mount register: mounts - name: Display mounted file systems debug: var: mounts.stdout_lines
Data Gathered
- identity
Identifies the host and checks for any actively logged-in users.
hostname, who - compute
Checks memory constraints, active processes, and overall CPU load over time.
free -h, top, loadavg, uptime - storage
Verifies disk space, active mount points, and file system inode availability.
df -h, df -i, mount
What the output looks like
When executed, Ansible uses the debug module to print the stored stdout from your shell commands. stdout_lines is specifically used for multi-line outputs like `df -h` to format it cleanly as a list.
Lessons from running this in production
The top -bn1 command generates a massive amount of output. Consider changing it to top -bn1 | head -n 15 so it doesn't flood your console.
Ansible actually natively gathers a lot of this data via gather_facts: yes! Hostname, uptime, memory, and mount data are available as built-in variables (e.g., ansible_memtotal_mb).
Using stdout_lines instead of stdout for tabular data (like df or free) prevents Ansible from printing it as one long string with \n characters.