-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade_fabric.yml
152 lines (110 loc) · 3.94 KB
/
upgrade_fabric.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
- hosts: switches
user: cumulus
serial: 1
tasks:
#########
#### check if the switch needs to be upgraded or not
- name: Register the OS version
shell: grep "VERSION_ID=" /etc/os-release | cut -d "=" -f 2
register: current_version
tags: register
- name: Check if switch needs to be upgraded or not
block:
- debug:
msg: "Switch needs to be upgraded from {{ current_version.stdout }} to {{ target_version }}"
#########
#### Check if the switch is doing L2 or only L3
- name: Check if the switch is doing L2 or only L3
shell: grep "clagd-enable" /etc/network/interfaces.d/interfaces | awk '{print $2}'
register: clagd_enabled
tags: register
#########
#### pre-flight checks applied to all the fabric switches
# Extecute the consistency checks on all the switches
- include_tasks: fabric_consistency.yml
#########
#### Stop critical services
- pause:
prompt: "Press any key to start the upgrade"
- name: Stop L2 services
block:
- debug:
msg: "Will stop L2 services"
- name: Register the clagd state
shell: /usr/bin/clagctl | grep "Our Priority" | awk '{ print $NF }'
register: clagd_state
tags: register
- name: Set clagd role as secondary
command: /usr/bin/clagctl priority 8200
become: true
when: clagd_state.stdout == "primary"
- name: Print clagd state
debug:
msg: "{{ clagd_state.stdout }}"
- name: Stop clagd service
systemd: state=stopped name=clagd
become: true
when: clagd_enabled.stdout == "yes"
- name: Stop FRR service
systemd: state=stopped name=frr
become: true
- name: Shutdown all the ports
script: files/shutdown_ports.sh
become: true
- pause:
prompt: "Validate that everything properly converged before doing the upgrade"
#########
#### Start update
- name: Upgrade system
become: true
apt:
update_cache: yes
autoremove: yes
upgrade: dist
allow_unauthenticated: yes
dpkg_options: 'force-confold'
#########
### Reboot system
- name: reboot system
shell: sleep 2 && shutdown -r now "Ansible package updates triggered"
async: 1
poll: 0
become: true
ignore_errors: true
- pause:
seconds: 5
- name: waiting for switch to come back
become: false
wait_for_connection:
timeout: 300
#########
### Ensure that system rebooted properly
- name: get system uptime
command: awk -F . '{print $1}' /proc/uptime
register: uptime
become: false
- name: verify a reboot was actually initiated
# machine should have started after it has been rebooted
fail:
msg: "Uptime is too high for reboot to have worked: {{ uptime.stdout }}s"
when: uptime.stdout|int > 300
#########
### post-flight checks
- name: POST register the OS version after upgrading
shell: grep "VERSION_ID=" /etc/os-release | cut -d "\"" -f 2
register: os_version_after
tags: register
- name: POST system version before and after upgrading
debug:
msg: "before: {{ current_version.stdout }}, after: {{ os_version_after.stdout }}"
# Wait a bit for everything to converge
- pause:
seconds: 40
# Execute the consistency checks on all the switches
- include_tasks: fabric_consistency.yml
when: current_version.stdout is version(target_version, '<')
- name: Check if switch needs to be upgraded or not
debug:
msg: "Switch is already running version {{ current_version.stdout }}"
when: current_version.stdout is version(target_version, '=')