ansible/playbooks/maintenance.yml

59 lines
2.1 KiB
YAML

---
- name: Run system maintenance
hosts: "{{ target_group | default('all') }}"
become: true
gather_facts: true
serial: "{{ maintenance_serial | default(maintenance_default_serial | default('100%')) }}"
vars:
# Default maintenance options
maintenance_update_cache: true
maintenance_upgrade_packages: true
maintenance_autoremove: true
maintenance_autoclean: true
maintenance_check_reboot: true
maintenance_allow_reboot: true
pre_tasks:
- name: Display maintenance target information
ansible.builtin.debug:
msg: |
Starting maintenance on: {{ inventory_hostname }}
Group: {{ group_names | join(', ') }}
Skip reboot: {{ skip_reboot | default(false) | bool }}
- name: Update apt cache
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
when: maintenance_update_cache | bool
roles:
- {role: maintenance, tags: ['maintenance']}
post_tasks:
- name: Display maintenance completion
ansible.builtin.debug:
msg: |
Maintenance completed for: {{ inventory_hostname }}
Reboot required: {{ maintenance_reboot_required.stat.exists | default(false) }}
{% if maintenance_reboot_required.stat.exists | default(false) and not (skip_reboot | default(false) | bool) %}
System will reboot automatically.
{% elif maintenance_reboot_required.stat.exists | default(false) and (skip_reboot | default(false) | bool) %}
System requires reboot but skip_reboot is set to true.
{% else %}
No reboot required.
{% endif %}
- name: Gather package facts after maintenance
ansible.builtin.package_facts:
manager: auto
- name: Display system information
ansible.builtin.debug:
msg: |
System: {{ ansible_facts['distribution'] }} {{ ansible_facts['distribution_version'] }}
Kernel: {{ ansible_facts['kernel'] }}
Architecture: {{ ansible_facts['architecture'] }}
Uptime: {{ ansible_facts['uptime_seconds'] | int // 3600 }}h {{ (ansible_facts['uptime_seconds'] | int % 3600) // 60 }}m