ansible-homelab/debian-update.yml

46 lines
1.2 KiB
YAML

---
- hosts: debianservers
gather_facts: true
become: true
tasks:
- name: Perform a cache update
ansible.builtin.apt:
update_cache: true
- name: Perform a dist-upgrade
ansible.builtin.apt:
upgrade: dist
- name: Check if backports are enabled in sources.list
ansible.builtin.lineinfile:
path: /etc/apt/sources.list
regex: "backports"
state: absent
changed_when: false
check_mode: true
register: backports
- name: Perform a dist-upgrade from Debian backports
ansible.builtin.apt:
default_release: bookworm-backports
update_cache: true
upgrade: dist
when:
- ansible_distribution == 'Debian'
- backports.found == 1
- name: Check if reboot is required
ansible.builtin.stat:
path: /var/run/reboot-required
get_checksum: false
register: reboot_required_file
- name: Reboot the server (if required)
ansible.builtin.reboot:
when: reboot_required_file.stat.exists == true
- name: Remove dependencies that are no longer required
ansible.builtin.apt:
autoremove: true