Project Overview📜
<span>ansible-HealthCheck</span>
is a server health check tool based on<span>Ansible</span>
. It automatically collects key information from servers (including operating system, CPU, memory, disk, network connections, etc.) and generates detailed<span>HTML</span>
inspection reports using<span>Jinja2</span>
templates. The reports can be sent via email and also previewed directly through a local<span>HTTP</span>
server, helping you quickly understand the operational status of the servers, making it a valuable assistant for operations and maintenance personnel.😊
Project Address:
https://github.com/liushiju/ansible-HealthCheck
You can clone the code directly and refer to the <span>README</span>
document to quickly get started with deployment and usage.
Features:
- • ⚡Automated Inspection: Orchestrate inspection tasks using
<span>Ansible Playbook</span>
for one-click automated inspections, significantly improving operational efficiency. - • 📊Multi-Dimensional Checks: Supports checks across multiple dimensions including CPU, memory, disk, network, and services, providing a comprehensive understanding of server operational status.
- • 🔧Flexible Expansion: Based on
<span>Ansible</span>
‘s modular design, it allows easy expansion of custom checks to meet personalized needs. - • 🖥️Visual Reports: Generates inspection reports in
<span>HTML</span>
format, intuitively displaying various data results. - • 📡Centralized Management: Achieve centralized inspection management through platforms like
<span>Ansible Tower</span>
or<span>AWX</span>
, enhancing operational efficiency.
Use Cases:
✅Routine Inspections: Regularly execute inspection tasks to promptly identify potential issues and ensure stable server operation.
🔍Troubleshooting: Quickly locate issues through inspection reports, reducing fault recovery time.
👥Batch Management: Suitable for inspecting large-scale server clusters, improving operational efficiency.
📧Report Archiving: Automatically send inspection reports to email for remote monitoring and historical data archiving, facilitating subsequent analysis.
Project Advantages:
⏱️Efficient Labor Savings: Automated data collection and report generation significantly reduce the workload of manual inspections, freeing up operational personnel.
📈Data Standardization: A unified report template ensures consistent formatting of inspection data, facilitating comparison and trend analysis.
🚨Real-Time Alerts: The report highlights abnormal statuses with color coding, helping operations personnel detect issues promptly.
⚙️Easy Deployment and Maintenance: The solution based on <span>Ansible</span>
is simple to deploy, requiring only minor configuration changes to adapt to different environments; it also supports flexible expansion of inspection items.
🌐Multiple Viewing Options: Reports can be sent directly via email or previewed online through a browser, meeting various operational needs.
✨Simple and User-Friendly: Based on <span>Ansible</span>
‘s declarative syntax, it is easy to get started without writing complex scripts.
🆓Open Source and Free: The project is open source and free to use and modify.
Project Deployment🚀
Conduct resource inspections on
<span>Linux</span>
systems, generating inspection reports that are sent via email to recipients.
1. Install Ansible
yum -y install epel-release
yum -y install ansible
ansible --version
2. Clone the Project Code
git clone https://github.com/liushiju/ansible-HealthCheck.git
cd ansible-HealthCheck
3. Modify the ansible.cfg Configuration
vi /root/ansible-HealthCheck-main/ansible.cfg
[root@centos ansible-HealthCheck-main]$grep -Ev "^$|#" ansible.cfg
[defaults]
host_key_checking=False
remote_user=root
filter_plugins=/root/ansible-HealthCheck-main/filter_plugins
[inventory]
[privilege_escalation]
[paramiko_connection]
[ssh_connection]
[persistent_connection]
[accelerate]
[selinux]
[colors]
[diff]
4. Configure the <span>hosts</span>
File
vi /root/ansible-HealthCheck-main/hosts
[root@centos ansible-HealthCheck-main]$grep -Ev "^$|#" hosts
[k8s]
192.168.31.31
192.168.31.32
192.168.31.33
192.168.31.34
192.168.31.35
192.168.31.36
192.168.31.37
192.168.31.61
192.168.31.62
192.168.31.63
192.168.31.64
192.168.31.65
192.168.31.66
[k8s:vars]
ansible_ssh_user="root"
ansible_ssh_pass="password"
Configure passwordless SSH (optional)
yum -y install sshpass
[root@centos ansible-HealthCheck-main]$cat /root/ssh_key_send.sh
#!/bin/sh
# rm -rf ~/.ssh/id_rsa*
# ssh-keygen -f ~/.ssh/id_rsa -P "" > /dev/null 2>&1
SSH_Pass=password
Key_Path=~/.ssh/id_rsa.pub
for ip in 31 32 33 34 35 36 37 61 62 63 64 65 66
do
sshpass -p $SSH_Pass ssh-copy-id -i $Key_Path "-o StrictHostKeyChecking=no" 192.168.31.$ip
done
Manually execute for non-standard port 22
sshpass -p "password" ssh-copy-id -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 192.168.31.30 -p 2201
5. Report and Email Configuration
Edit
<span>vi /root/ansible-HealthCheck-main/os-check/defaults/main.yaml</span>
file and modify the following content:
- • Report Directory:
<span>check_report_path</span>
Set the report generation directory (e.g.,<span>/tmp</span>
). - • SMTP Related Variables (
<span>check_mail_host</span>
,<span>check_mail_port</span>
,<span>check_mail_username</span>
,<span>check_mail_password</span>
,<span>check_mail_to</span>
) fill in according to actual conditions.
6. Execute the Playbook
cd /root/ansible-HealthCheck-main
ansible-playbook -i hosts roles/os-check.yaml --limit k8s
7. View Inspection Reports via Browser
# Run in foreground
cd /tmp/ && python -m SimpleHTTPServer 30000
# Run in background
cd /tmp/ && nohup python -m SimpleHTTPServer 30000 >/dev/null 2>&1 &
Open in browser:
<span>http://IP:30000/report-2025-xx-xx.html</span>
8. Schedule Task Execution
/root/ansible-HealthCheck-main/auto-check.sh
#!/bin/sh
cd /root/ansible-HealthCheck-main
ansible-playbook -i hosts roles/os-check.yaml --limit k8s
crontab -l
1 0 * * * /bin/sh /root/ansible-HealthCheck-main/auto-check.sh > /root/ansible-HealthCheck-main/auto-check.log 2>&1
Effect Preview🎉
More Information:
- • Visit the ansible-HealthCheck GitHub repository[1] for more information.
- • Hope this document helps you quickly understand ansible-HealthCheck!
👉 Follow me for more interesting open-source tool shares!
Citation Links
<span>[1]</span>
GitHub Repository: https://github.com/liushiju/ansible-HealthCheck