# Maintenance Role Handles system maintenance tasks including package updates, cleanup, and conditional reboots. ## Requirements - Debian/Ubuntu-based systems with `apt` package manager - `sudo` privileges for package management and system operations ## Role Variables ### Default Variables (`defaults/main.yml`) ```yaml # Package management maintenance_update_cache: true # Update apt cache before operations maintenance_upgrade_packages: true # Perform dist-upgrade maintenance_autoremove: true # Remove unused packages maintenance_autoclean: true # Clean apt cache # Reboot handling maintenance_check_reboot: true # Check if reboot is required maintenance_allow_reboot: true # Allow automatic reboots ``` ### Host Variables ```yaml skip_reboot: true # Skip reboots for this host (optional) ``` ### Playbook Variables ```yaml maintenance_serial: "100%" # Serial execution (e.g., "1" for one-at-a-time) target_group: "all" # Target host group ``` ## Dependencies None. ## Example Playbook ### Basic Usage ```yaml - hosts: servers become: true roles: - maintenance ``` ### With Custom Variables ```yaml - hosts: servers become: true vars: maintenance_allow_reboot: false # Disable automatic reboots roles: - maintenance ``` ### Using the Dedicated Maintenance Playbook ```bash # Run on all hosts ansible-playbook maintenance-playbook.yml # Run on specific group ansible-playbook maintenance-playbook.yml -e "target_group=dev" # Run with serial execution ansible-playbook maintenance-playbook.yml -e "target_group=dev" -e "maintenance_serial=1" # Dry-run ansible-playbook maintenance-playbook.yml --check --diff ``` ### Using Makefile (Recommended) ```bash # Basic usage make maintenance # All hosts make maintenance GROUP=dev # Specific group make maintenance HOST=dev01 # Specific host make maintenance CHECK=true # Dry-run # Advanced options make maintenance GROUP=dev SERIAL=1 # Serial execution make maintenance GROUP=local # Local machine (auto-sudo) ``` ## Tasks Performed 1. **Package Updates**: Performs `apt dist-upgrade` to update all packages 2. **Cleanup**: Removes unused packages (`apt autoremove`) and cleans cache (`apt autoclean`) 3. **Reboot Check**: Checks if `/var/run/reboot-required` exists 4. **Conditional Reboot**: Reboots system if required (unless `skip_reboot=true`) ## Reboot Behavior The role respects the following reboot conditions: - Only reboots if `/var/run/reboot-required` exists - Only on `apt`-based systems (`ansible_facts['pkg_mgr'] == "apt"`) - Skips reboot if `skip_reboot` is set to `true` in host variables - Provides informative reboot message ## Integration with Maintenance Playbook This role is designed to work with the dedicated `maintenance-playbook.yml` which provides: - Flexible host targeting - Serial execution support - Detailed progress reporting - System information display - Intelligent sudo handling ## License BSD ## Author Information Part of the Ansible Development Environment Setup project.