From 66ff89acd1a9ed65c5a5786ce54a855612879be0 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 7 Jul 2025 11:25:10 +0700 Subject: [PATCH] Add system maintenance playbook --- playbooks/system-maintenance.yml | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 playbooks/system-maintenance.yml diff --git a/playbooks/system-maintenance.yml b/playbooks/system-maintenance.yml new file mode 100644 index 0000000..bf58955 --- /dev/null +++ b/playbooks/system-maintenance.yml @@ -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'