Maintenance Role
Handles system maintenance tasks including package updates, cleanup, and conditional reboots.
Requirements
- Debian/Ubuntu-based systems with
aptpackage manager sudoprivileges for package management and system operations
Role Variables
Default Variables (defaults/main.yml)
# 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
skip_reboot: true # Skip reboots for this host (optional)
Playbook Variables
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
- hosts: servers
become: true
roles:
- maintenance
With Custom Variables
- hosts: servers
become: true
vars:
maintenance_allow_reboot: false # Disable automatic reboots
roles:
- maintenance
Using the Dedicated Maintenance Playbook
# 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)
# 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
- Package Updates: Performs
apt dist-upgradeto update all packages - Cleanup: Removes unused packages (
apt autoremove) and cleans cache (apt autoclean) - Reboot Check: Checks if
/var/run/reboot-requiredexists - 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-requiredexists - Only on
apt-based systems (ansible_facts['pkg_mgr'] == "apt") - Skips reboot if
skip_rebootis set totruein 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.