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_linesData 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.
terminal snippet
TASK [Display RAM usage] ********************************
ok: [db-server-01] => {
"memory.stdout_lines": [
" total used free shared buff/cache available",
"Mem: 15Gi 2.1Gi 9.3Gi 120Mi 3.6Gi 12Gi",
"Swap: 4.0Gi 0B 4.0Gi"
]
}
$