Adjusted apt update to provide a feedback if upgrade is needed and wait one hour for cache update. Added localhost entity into the hosts.ini

This commit is contained in:
2025-08-24 16:28:36 +02:00
parent 0703b178dc
commit c0a48d6c4d
2 changed files with 21 additions and 12 deletions

View File

@@ -18,7 +18,7 @@ raspberry-pi ansible_host=x.x.x.x
[lxc]
ansible ansible_host=x.x.x.x
zabbix-proxy ansible_host=x.x.x.x
pi-hole ansible_host=x.x.x.x
localhost ansible_connection=local # for testing playbooks on the control node
[proxmox_backup]
proxmox-backup ansible_host=x.x.x.x

View File

@@ -1,14 +1,23 @@
- name: Upgrade packages
---
- name: Upgrade all apt packages
hosts: ubuntu
become: true
become: yes
tasks:
- name: Update cache
ansible.builtin.apt:
update_cache: true
register: cache_updated
- name: Update apt cache
ansible.builtin.apt:
update_cache: yes
cache_valid_time: 3600
- name: Upgrade packages if something is changed
ansible.builtin.apt:
upgrade: "yes"
when: cache_updated.changed
- name: Upgrade all apt packages
ansible.builtin.apt:
upgrade: dist
- name: Check if a reboot is required
ansible.builtin.stat:
path: /var/run/reboot-required
register: reboot_required_file
- name: Display reboot message
ansible.builtin.debug:
msg: "A reboot is required to apply the latest updates."
when: reboot_required_file.stat.exists