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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user