Add system maintenance playbook
This commit is contained in:
parent
0b462ae50c
commit
66ff89acd1
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
- 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'
|
Loading…
Reference in New Issue