47 lines
1.4 KiB
YAML
47 lines
1.4 KiB
YAML
|
---
|
||
|
- name: Update apt repo and cache
|
||
|
apt:
|
||
|
update_cache: true
|
||
|
force_apt_get: true
|
||
|
cache_valid_time: 3600
|
||
|
|
||
|
- name: Upgrade all packages
|
||
|
apt:
|
||
|
upgrade: full
|
||
|
force_apt_get: true
|
||
|
autoremove: true
|
||
|
register: upgrade_cmd
|
||
|
|
||
|
- name: List newly installed and upgraded packages
|
||
|
shell: grep -E "^$(date +%Y-%m-%d).+ (install|upgrade) " /var/log/dpkg.log |cut -d " " -f 3-5
|
||
|
register: new_or_upgraded_pkgs
|
||
|
when: upgrade_cmd.changed
|
||
|
|
||
|
- name: Show installed/updated packages output
|
||
|
debug:
|
||
|
msg: "{{ new_or_upgraded_pkgs is defined and new_or_upgraded_pkgs.stdout_lines }}"
|
||
|
when: new_or_upgraded_pkgs.changed
|
||
|
|
||
|
- name: Check if a reboot is needed
|
||
|
stat:
|
||
|
path: /var/run/reboot-required
|
||
|
register: reboot_required_file
|
||
|
|
||
|
- name: Check if a docker upgrade happened
|
||
|
set_fact:
|
||
|
docker_upgrade: "{{ new_or_upgraded_pkgs is defined and 'stdout_lines' in new_or_upgraded_pkgs and 'docker' in new_or_upgraded_pkgs.stdout_lines }}"
|
||
|
|
||
|
- name: Output warning when reboot is needed
|
||
|
debug:
|
||
|
msg: "--- WARNING: REBOOT REQUIRED ---"
|
||
|
when: reboot_required_file.stat.exists | bool or docker_upgrade | bool
|
||
|
|
||
|
- name: Show prompt to take note of reboot
|
||
|
pause:
|
||
|
prompt: |
|
||
|
"{{ inventory_hostname }} requires a reboot, please take note and perform
|
||
|
this manually after this role finishes! Thank you for your system admin
|
||
|
labours!"
|
||
|
delegate_to: localhost
|
||
|
when: reboot_required_file.stat.exists | bool or docker_upgrade | bool
|