Update centos.yaml
This commit is contained in:
18
centos.yaml
18
centos.yaml
@@ -12,9 +12,14 @@
|
||||
debug:
|
||||
msg: "{{ logged_users.stdout }} user(s) currently logged in"
|
||||
|
||||
- name: Skip updates if users are logged in
|
||||
meta: end_play
|
||||
when: logged_users.stdout | int > 1
|
||||
- name: Check if we should skip this host
|
||||
set_fact:
|
||||
skip_updates: "{{ logged_users.stdout | int > 1 }}"
|
||||
|
||||
- name: Host will be skipped due to logged in users
|
||||
debug:
|
||||
msg: "Host: {{ inventory_hostname }} - Skipping updates due to {{ logged_users.stdout }} users logged in"
|
||||
when: skip_updates
|
||||
|
||||
- name: Ensure all packages are up to date
|
||||
dnf:
|
||||
@@ -22,6 +27,7 @@
|
||||
state: latest
|
||||
update_cache: yes
|
||||
register: dnf_result
|
||||
when: not skip_updates
|
||||
|
||||
- name: Display package update statistics
|
||||
debug:
|
||||
@@ -30,13 +36,13 @@
|
||||
- "Packages installed: {{ dnf_result.results | select('match', '^Installed:.*') | list | length }}"
|
||||
- "Packages updated: {{ dnf_result.results | select('match', '^Updated:.*') | list | length }}"
|
||||
- "Packages removed: {{ dnf_result.results | select('match', '^Removed:.*') | list | length }}"
|
||||
when: dnf_result.changed and dnf_result.results is defined
|
||||
when: not skip_updates and dnf_result.changed and dnf_result.results is defined
|
||||
|
||||
- name: No updates needed
|
||||
debug:
|
||||
msg: "Host: {{ inventory_hostname }} - System is already up to date"
|
||||
when: not dnf_result.changed
|
||||
when: not skip_updates and not dnf_result.changed
|
||||
|
||||
- name: Rebooting the servers
|
||||
reboot:
|
||||
when: dnf_result.changed
|
||||
when: not skip_updates and dnf_result.changed
|
||||
Reference in New Issue
Block a user