forked from ceph/ceph-ansible
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate-servers.yml
88 lines (71 loc) · 2.26 KB
/
update-servers.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
- name: confirm whether user really meant to update servers
hosts: localhost
gather_facts: false
vars_prompt:
- name: ireallymeanit
prompt: Are you sure you want to update each node ?
default: 'no'
private: no
tasks:
- name: exit playbook, if user did not mean to update servers
fail:
msg: >
"Exiting update-server playbook, servers were NOT updated.
To update servers, either say 'yes' on the prompt or
or use `-e ireallymeanit=yes` on the command line when
invoking the playbook"
when: ireallymeanit != 'yes'
- hosts: all
gather_facts: false
any_errors_fatal: true
become: true
serial: 10 # Increase to update more servers at once
tags: always
vars:
delegate_facts_host: True
tasks:
- name: Flush yum cache
shell: yum clean all
args:
warn: false
- name: check packages for updates
shell: yum list updates | awk 'f;/Updated Packages/{f=1;}' | awk '{ print $1 }'
changed_when: updates.stdout_lines | length > 0
args:
warn: false
register: updates
- name: display count
debug:
msg: "Found {{ updates.stdout_lines | length }} packages to be updated:\n\n{{ updates.stdout }}"
- when: updates.stdout_lines | length > 0
block:
- name: install updates using Generic OS package manager
package:
name: "*"
state: latest
- name: install yum-utils
package:
name: yum-utils
state: latest
- name: check if reboot is required
shell: needs-restarting -r
failed_when: false
register: reboot_required
changed_when: false
- when: updates.stdout_lines | length > 0 and reboot_required.rc != 0
block:
- name: reboot the server if required
shell: sleep 3; reboot
ignore_errors: true
changed_when: false
async: 1
poll: 0
- name: wait for server to come back after reboot
wait_for_connection:
timeout: 600
delay: 20
register: reboot_result
- name: reboot time
debug:
msg: "The system rebooted in {{ reboot_result.elapsed }} seconds."