Files
homelab/roles/base/tasks/system_update.yml
2025-09-10 21:43:11 +10:00

49 lines
1.1 KiB
YAML

---
- name: Ensure debian-archive-keyring is installed
apt:
name: debian-archive-keyring
state: present
update_cache: yes
become: yes
- name: Update APT cache
apt:
update_cache: yes
force_apt_get: yes
when: ansible_distribution in ['Debian', 'Ubuntu']
- name: Upgrade all packages to latest
apt:
name: "*"
state: latest
force_apt_get: yes
when: ansible_distribution in ['Debian', 'Ubuntu']
register: upgrade_result
- name: Dist-upgrade packages
apt:
upgrade: dist
force_apt_get: yes
when: ansible_distribution in ['Debian', 'Ubuntu']
register: dist_upgrade_result
- name: Install required packages
apt:
name: "{{ install_packages }}"
state: present
become: yes
when: ansible_distribution in ['Debian', 'Ubuntu']
register: install_result
- name: Reboot if required after updates
reboot:
reboot_timeout: 600
test_command: whoami
when:
- upgrade_result.changed or dist_upgrade_result.changed or install_result.changed
- ansible_virtualization_type != "lxc"
become: yes
- name: Gather facts after reboot
setup: