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] [lxc]
ansible ansible_host=x.x.x.x ansible ansible_host=x.x.x.x
zabbix-proxy 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]
proxmox-backup ansible_host=x.x.x.x proxmox-backup ansible_host=x.x.x.x

View File

@@ -1,14 +1,23 @@
- name: Upgrade packages ---
- name: Upgrade all apt packages
hosts: ubuntu hosts: ubuntu
become: true become: yes
tasks: tasks:
- name: Update cache - name: Update apt cache
ansible.builtin.apt: ansible.builtin.apt:
update_cache: true update_cache: yes
register: cache_updated cache_valid_time: 3600
- name: Upgrade packages if something is changed - name: Upgrade all apt packages
ansible.builtin.apt: ansible.builtin.apt:
upgrade: "yes" upgrade: dist
when: cache_updated.changed
- 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