I have around 12 Debian-based VMs running in my homelab. A while ago, I used to update them all manually — one by one. SSH into each machine, run apt update && apt upgrade
, wait, reboot if needed… then repeat. It worked, but it was slow, boring, and very easy to forget one or two machines.
Now I use Ansible to handle everything for me. I wrote a simple playbook, and with just one command, all my VMs update in parallel. If any of them need a reboot, Ansible checks for that and takes care of it too. I just run the playbook and let the automation do the heavy lifting.
It saves me a ton of time, and honestly, it feels kind of awesome. I watch logs scroll by across multiple machines at once — and sip coffee like a sysadmin with superpowers 🙂
---
- name: Upgrade Debian-based systems
hosts: homelab
become: true
vars:
reboot_flag_path: /var/run/reboot-required
tasks:
- name: Update apt package index
apt:
update_cache: yes
register: apt_update_result
ignore_errors: no
- name: Upgrade installed packages
apt:
upgrade: dist
register: apt_upgrade_result
ignore_errors: yes
retries: 3
delay: 10
until: apt_upgrade_result is succeeded
- name: Show upgrade results
debug:
var: apt_upgrade_result
- name: Check if a reboot is required
stat:
path: "{{ reboot_flag_path }}"
register: reboot_check
- name: Reboot system if needed
reboot:
msg: "System will automatically reboot after upgrade"
pre_reboot_delay: 10
post_reboot_delay: 30
reboot_timeout: 600
when: reboot_check.stat.exists
register: reboot_result
- name: Report whether a reboot was performed
debug:
msg: >-
{% raw %}{% if reboot_check.stat.exists %}{% endraw %}
System was rebooted.
{% raw %}{% else %}{% endraw %}
No reboot required.
{% raw %}{% endif %}{% endraw %}