42 lines
986 B
YAML
42 lines
986 B
YAML
---
|
|
- name: System Maintenance Tasks
|
|
hosts: all
|
|
become: yes
|
|
tasks:
|
|
- name: Update package repositories
|
|
apt:
|
|
update_cache: yes
|
|
|
|
- name: Install security updates
|
|
apt:
|
|
upgrade: dist
|
|
|
|
- name: Clean temporary files
|
|
file:
|
|
path: /tmp
|
|
state: absent
|
|
notify: Recreate /tmp
|
|
|
|
- name: Restart services if needed
|
|
shell: |
|
|
needs_restart=$(needs-restarting || true)
|
|
if [ -n "$needs_restart" ]; then
|
|
systemctl restart apache2
|
|
fi
|
|
when: ansible_os_family == "Debian"
|
|
|
|
- name: Generate system health report
|
|
shell: |
|
|
echo "System Health Report - $(date)" > /var/log/system_health.log
|
|
uptime >> /var/log/system_health.log
|
|
df -h >> /var/log/system_health.log
|
|
free -m >> /var/log/system_health.log
|
|
register: health_report
|
|
|
|
handlers:
|
|
- name: Recreate /tmp
|
|
file:
|
|
path: /tmp
|
|
state: directory
|
|
mode: '1777'
|