initial commit
This commit is contained in:
48
roles/system-maintenance/README.md
Normal file
48
roles/system-maintenance/README.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# System Maintenance Role
|
||||
|
||||
Updates packages and handles system maintenance tasks across multiple distributions.
|
||||
|
||||
## Features
|
||||
|
||||
- Multi-distribution support (Debian/Ubuntu/Alpine)
|
||||
- Package cache updates and upgrades
|
||||
- Automatic cleanup of unused packages
|
||||
- Reboot handling when required
|
||||
- Distribution detection and validation
|
||||
|
||||
## Supported Distributions
|
||||
|
||||
- **Debian/Ubuntu** - Updates via apt, removes unused packages, checks for reboot requirements
|
||||
- **Alpine** - Updates via apk package manager
|
||||
|
||||
## Usage
|
||||
|
||||
```yaml
|
||||
- name: Perform system maintenance
|
||||
include_role:
|
||||
name: system-maintenance
|
||||
```
|
||||
|
||||
## What It Does
|
||||
|
||||
### Debian/Ubuntu Systems
|
||||
1. Updates package cache (6-hour validity)
|
||||
2. Upgrades all packages
|
||||
3. Removes unused packages and purges configs
|
||||
4. Checks if reboot is required
|
||||
5. Triggers reboot handler if needed
|
||||
|
||||
### Alpine Systems
|
||||
1. Updates package cache
|
||||
2. Upgrades all packages
|
||||
|
||||
## Requirements
|
||||
|
||||
- Root privileges
|
||||
- Supported distribution (Debian/Ubuntu/Alpine)
|
||||
|
||||
## Notes
|
||||
|
||||
- Role automatically detects distribution and uses appropriate tasks
|
||||
- Fails gracefully on unsupported distributions
|
||||
- Reboot is handled via handler (only when required on Debian/Ubuntu)
|
||||
4
roles/system-maintenance/handlers/main.yaml
Executable file
4
roles/system-maintenance/handlers/main.yaml
Executable file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
- name: Reboot system
|
||||
ansible.builtin.reboot:
|
||||
msg: Rebooting as a reboot is required after upgrade
|
||||
6
roles/system-maintenance/tasks/alpine.yaml
Executable file
6
roles/system-maintenance/tasks/alpine.yaml
Executable file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
- name: Update and upgrade apk packages (Alpine)
|
||||
community.general.apk:
|
||||
upgrade: true
|
||||
update_cache: true
|
||||
when: ansible_os_family == 'Alpine'
|
||||
22
roles/system-maintenance/tasks/debian.yaml
Executable file
22
roles/system-maintenance/tasks/debian.yaml
Executable file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
- name: Update and upgrade apt packages (Debian/Ubuntu)
|
||||
ansible.builtin.apt:
|
||||
upgrade: true
|
||||
update_cache: true
|
||||
cache_valid_time: 21600 # 6 hours
|
||||
|
||||
- name: Remove unused packages
|
||||
ansible.builtin.apt:
|
||||
autoremove: true
|
||||
purge: true
|
||||
|
||||
- name: Check if reboot required
|
||||
ansible.builtin.stat:
|
||||
path: /var/run/reboot-required
|
||||
register: reboot_required_file
|
||||
|
||||
- name: Call reboot handler if reboot required
|
||||
ansible.builtin.debug:
|
||||
msg: "Reboot is required"
|
||||
when: reboot_required_file.stat.exists
|
||||
notify: Reboot system
|
||||
19
roles/system-maintenance/tasks/main.yaml
Executable file
19
roles/system-maintenance/tasks/main.yaml
Executable file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
- name: Use appropriate tasks for given distribution
|
||||
ansible.builtin.set_fact:
|
||||
task_distro_file: "{{ ansible_os_family | lower }}.yaml"
|
||||
|
||||
- name: Verify that the distribution is supported
|
||||
become: false
|
||||
ansible.builtin.stat:
|
||||
path: "{{ role_path }}/tasks/{{ task_distro_file }}"
|
||||
register: distro_stat_result
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Fail if the distribution is not supported
|
||||
ansible.builtin.fail:
|
||||
msg: "Unsupported distribution: {{ ansible_os_family }}"
|
||||
when: not distro_stat_result.stat.exists
|
||||
|
||||
- name: Include distribution specific update tasks
|
||||
ansible.builtin.include_tasks: "{{ task_distro_file }}"
|
||||
Reference in New Issue
Block a user