forked from confluentinc/cp-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade_zookeeper.yml
257 lines (225 loc) · 8.74 KB
/
upgrade_zookeeper.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
---
- name: Zookeeper Upgrade - Prep
hosts: zookeeper
gather_facts: false
# Running serial=1 because add_host has problems
# https://stackoverflow.com/questions/42106527/ansible-how-to-call-module-add-host-for-all-hosts-of-the-play
serial: 1
tags:
- prep
tasks:
- name: Gather OS Facts
setup:
# Only gathers items in list, filters out the rest
filter: ansible_os_family
gather_subset:
- '!all'
- import_role:
name: confluent.variables
- name: Load override.conf
slurp:
src: "{{ zookeeper.systemd_override }}"
register: slurped_override
when: installation_method == "archive"
- name: Set zookeeper_current_version variable - Archive Installer
set_fact:
zookeeper_current_version: "{{ (slurped_override.content|b64decode) .split('\n') |
select('match', '^ExecStart=' + archive_config_base_path + '/confluent-(.*)/bin/zookeeper-server-start ' + zookeeper.config_file) |
list | first | regex_search('[0-9]+(.[0-9]+)+') }}"
when: installation_method == "archive"
- name: Zookeeper is Running
systemd:
name: "{{zookeeper_service_name}}"
state: started
- name: Zookeeper Health Check
import_role:
name: confluent.zookeeper
tasks_from: health_check.yml
vars:
archive_version: "{{zookeeper_current_version | default(confluent_package_version)}}"
when: not ansible_check_mode
- name: Get Package Facts
package_facts:
manager: auto
when: installation_method == "package"
- set_fact:
confluent_server_enabled: "{{ True if ansible_facts.packages['confluent-server'] is defined else False }}"
confluent_kafka_upgraded: "{{ True if ansible_facts.packages['confluent-kafka'] is defined else False }}"
when: installation_method == "package"
- name: Set Current Package Version of confluent-server
set_fact:
zookeeper_current_version: "{{ ansible_facts.packages['confluent-server'][0]['version'] }}"
when:
- confluent_server_enabled|bool
- installation_method == "package"
- name: Set Current Package Version of confluent-kafka-2.12
set_fact:
zookeeper_current_version: "{{ ansible_facts.packages['confluent-kafka-2.12'][0]['version'] }}"
when:
- not confluent_server_enabled|bool
- not confluent_kafka_upgraded|bool
- installation_method == "package"
- name: Set Current Package Version of confluent-kafka
set_fact:
zookeeper_current_version: "{{ ansible_facts.packages['confluent-kafka'][0]['version'] }}"
when:
- not confluent_server_enabled|bool
- confluent_kafka_upgraded|bool
- installation_method == "package"
- debug:
msg: "Current version: {{zookeeper_current_version}} Upgrade to version: {{confluent_package_version}}"
- name: Get Leader/Follower
shell: "{{zookeeper_health_check_command}} | grep Mode"
args:
executable: /bin/bash
register: leader_query
changed_when: false
check_mode: false
- name: Add host to Follower Group
add_host:
name: "{{ inventory_hostname }}"
group: upgrade_zookeeper_followers
delegate_to: localhost
when:
- '"follower" in leader_query.stdout'
- zookeeper_current_version != confluent_full_package_version
- zookeeper_current_version != confluent_package_version
- name: Add host to Leader Group
add_host:
name: "{{ inventory_hostname }}"
group: upgrade_zookeeper_leader
delegate_to: localhost
when:
- '"leader" in leader_query.stdout'
- zookeeper_current_version != confluent_full_package_version
- zookeeper_current_version != confluent_package_version
- debug:
msg: "Leader: {{inventory_hostname}}"
when: '"leader" in leader_query.stdout'
- name: Zookeeper Upgrade
# Putting leader group last here with serial=1 so the leader runs last
hosts: upgrade_zookeeper_followers,upgrade_zookeeper_leader
environment: "{{ proxy_env }}"
serial: 1
tags:
- upgrade
tasks:
- import_role:
name: confluent.variables
- name: Create Backup Directory
file:
path: "/tmp/upgrade/{{ zookeeper_service_name }}"
state: directory
mode: 0640
- set_fact:
timestamp: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
- name: Backup Zookeeper Configuration files
copy:
src: "{{ item }}"
remote_src: true
dest: "/tmp/upgrade/{{ zookeeper_service_name }}/{{ item | basename }}-{{timestamp}}"
loop:
- "{{ zookeeper.config_file }}"
- "{{ zookeeper.systemd_override }}"
- "{{ kafka_broker.config_file }}"
# Files cannot be copied because directory is not created in check mode
ignore_errors: "{{ ansible_check_mode }}"
when: installation_method == "package"
- name: Stop Service
systemd:
name: "{{ zookeeper_service_name }}"
state: stopped
- name: Wait for Zookeeper Status on Another Zookeeper Node
import_role:
name: confluent.zookeeper
tasks_from: health_check.yml
delegate_to: "{{ groups['zookeeper'] | difference([inventory_hostname]) | first }}"
vars:
zookeeper_health_check_host: "{{ groups['zookeeper'] | difference([inventory_hostname]) | first }}"
when: not ansible_check_mode
- name: Configure Repositories
import_role:
name: confluent.common
vars:
install_java: false
- name: Remove Confluent-Kafka Packages - Red Hat
yum:
name: confluent-kafka-2.12
state: absent
when:
- ansible_os_family == "RedHat"
- not confluent_server_enabled|bool
- installation_method == "package"
# Packages will not be found in check mode because repos not changed
ignore_errors: "{{ ansible_check_mode }}"
- name: Remove Confluent-Kafka Packages - Debian
apt:
name: confluent-kafka-2.12
state: absent
when:
- ansible_os_family == "Debian"
- not confluent_server_enabled|bool
- installation_method == "package"
# Packages will not be found in check mode because repos not changed
ignore_errors: "{{ ansible_check_mode }}"
- name: Install the Packages - Red Hat
yum:
name: "{{item}}{{confluent_package_redhat_suffix}}"
state: latest
update_cache: true
loop: "{{ zookeeper_packages }}"
when:
- ansible_os_family == "RedHat"
- installation_method == "package"
# Packages will not be found in check mode because repos not changed
ignore_errors: "{{ ansible_check_mode }}"
- name: Install the Packages - Debian
apt:
name: "{{item}}{{confluent_package_debian_suffix}}"
update_cache: true
loop: "{{ zookeeper_packages }}"
when:
- ansible_os_family == "Debian"
- installation_method == "package"
# Packages will not be found in check mode because repos not changed
ignore_errors: "{{ ansible_check_mode }}"
- name: Put back configuration
copy:
dest: "{{ item }}"
remote_src: true
src: "/tmp/upgrade/{{ zookeeper_service_name }}/{{ item | basename }}-{{timestamp}}"
loop:
- "{{ zookeeper.config_file }}"
- "{{ kafka_broker.config_file }}"
# Files cannot be copied because directory is not created in check mode
ignore_errors: "{{ ansible_check_mode }}"
when: installation_method == "package"
- name: Copy Zookeeper Service from Archive Directory to System
copy:
src: "{{binary_base_path}}/lib/systemd/system/{{zookeeper.systemd_file|basename}}"
remote_src: true
dest: "{{zookeeper.systemd_file}}"
mode: 0644
force: true
when: installation_method == "archive"
- name: Update Override to Use New Version
lineinfile:
path: "{{ zookeeper.systemd_override }}"
line: "ExecStart={{archive_config_base_path}}/confluent-{{confluent_package_version}}/bin/zookeeper-server-start {{ zookeeper.config_file }}"
regexp: "ExecStart={{archive_config_base_path}}/confluent-(.*)/bin/zookeeper-server-start {{ zookeeper.config_file }}"
when: installation_method == "archive"
- name: Add Disable Admin Server Property
lineinfile:
name: "{{zookeeper.config_file}}"
line: admin.enableServer=false
regexp: admin.enableServer=.*
- name: Restart Service
systemd:
daemon_reload: true
name: "{{ zookeeper_service_name }}"
state: restarted
- name: Zookeeper Health Check
import_role:
name: confluent.zookeeper
tasks_from: health_check.yml
when: not ansible_check_mode