forked from confluentinc/cp-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade_kafka_broker.yml
176 lines (154 loc) · 5.84 KB
/
upgrade_kafka_broker.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
---
- name: Kafka Broker - Host Ordering
hosts: kafka_broker
# 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
tasks:
- name: Set confluent_server_enabled and kafka_broker_jolokia_ssl_enabled Variables
include_tasks: tasks/set_kafka_broker_jolokia_ssl_enabled.yml
- name: Create Ordered Kafka Broker Groups
import_tasks: tasks/create_ordered_kafka_groups.yml
vars:
controller_group: controller
non_controller_group: non_controllers
- name: Kafka Broker Upgrade - Config Prep
hosts: non_controllers,controller
gather_facts: false
serial: 1
vars:
kafka_broker_upgrade_start_version: "5.3"
tasks:
- import_role:
name: confluent.variables_handlers
- set_fact:
inter_broker_protocol_version: 2.3
log_message_format_version: 2.3
when: kafka_broker_upgrade_start_version is match('5.3.*')
- set_fact:
inter_broker_protocol_version: 2.4
log_message_format_version: 2.4
when: kafka_broker_upgrade_start_version is match('5.4.*')
- name: Set Inter-Broker Protocol Version to Current Version
lineinfile:
name: "{{kafka_broker.config_file}}"
line: "inter.broker.protocol.version={{inter_broker_protocol_version}}"
regexp: inter.broker.protocol.version.*
state: present
- name: Set Log Message Format Version to Current Version
lineinfile:
name: "{{kafka_broker.config_file}}"
line: "log.message.format.version={{log_message_format_version}}"
regexp: log.message.format.version.*
state: present
- name: Make sure Controlled Shutdown Property is not set to False
lineinfile:
name: "{{kafka_broker.config_file}}"
# Default value for controlled.shutdown.enable is true
# Removing the line and restarting the service will set property to true
line: controlled.shutdown.enable=false
state: absent
notify:
- Restart Kafka
- Wait for URP
- name: Kafka Broker Upgrade - Host Ordering
hosts: kafka_broker
serial: 1
tasks:
# Sets active_controller_count var for each host
- name: Create Ordered Kafka Broker Groups
import_tasks: tasks/create_ordered_kafka_groups.yml
vars:
controller_group: controller
non_controller_group: non_controllers
- name: Set Current Package Version
set_fact:
kafka_broker_current_version: "{{ ansible_facts.packages['confluent-server'][0]['version'] }}"
when: confluent_server_enabled|bool
- name: Set Current Package Version
set_fact:
kafka_broker_current_version: "{{ ansible_facts.packages['confluent-kafka-2.12'][0]['version'] }}"
when: not confluent_server_enabled|bool
- debug:
msg: "Current version: {{kafka_broker_current_version}} Upgrade to version: {{confluent_package_version}}"
- name: Add host to Non Controller Group
add_host:
name: "{{ inventory_hostname }}"
group: upgrade_non_controllers
delegate_to: localhost
when:
- active_controller_count|int == 0
- kafka_broker_current_version != confluent_full_package_version
- kafka_broker_current_version != confluent_package_version
- name: Add host to Controller Group
add_host:
name: "{{ inventory_hostname }}"
group: upgrade_controller
delegate_to: localhost
when:
- active_controller_count|int == 1
- kafka_broker_current_version != confluent_full_package_version
- kafka_broker_current_version != confluent_package_version
- name: Kafka Broker Upgrade
# Putting controller group last here with serial=1 has the controller as the last host to run
hosts: upgrade_non_controllers,upgrade_controller
environment: "{{ proxy_env }}"
serial: 1
tags:
- upgrade
tasks:
- import_role:
name: confluent.variables_handlers
- name: Upgrade Kafka Broker
include_tasks: tasks/upgrade_component.yml
vars:
service_name: "{{ kafka_broker_service_name }}"
packages: "{{ kafka_broker_packages }}"
backup_files:
- "{{ kafka_broker.config_file }}"
- "{{ kafka_broker.systemd_override }}"
- "{{ zookeeper.config_file }}"
restore_files:
- "{{ kafka_broker.config_file }}"
- "{{ zookeeper.config_file }}"
- name: Wait for Under Replicated Partitions on Broker
import_tasks: tasks/wait_for_urp.yml
# Kafka Restarted, need to figure out the new controller
- name: Kafka Broker - Host Ordering
hosts: kafka_broker
serial: 1
tasks:
- name: Create Ordered Kafka Broker Groups
import_tasks: tasks/create_ordered_kafka_groups.yml
vars:
controller_group: kafka_broker_controller
non_controller_group: kafka_broker_non_controllers
- name: Kafka Broker Upgrade - Set Inter-Broker Protocol to Current Version
hosts: kafka_broker_non_controllers,kafka_broker_controller
gather_facts: false
serial: 1
tags:
- inter_broker_protocol_version
vars:
upgrade_to_version: "5.5"
tasks:
- import_role:
name: confluent.variables_handlers
- set_fact:
inter_broker_protocol_version: 2.3
when: upgrade_to_version is match('5.3.*')
- set_fact:
inter_broker_protocol_version: 2.4
when: upgrade_to_version is match('5.4.*')
- set_fact:
inter_broker_protocol_version: 2.5
when: upgrade_to_version is match('5.5.*')
- name: Set Inter-Broker Protocol Version to Current Version
lineinfile:
name: "{{kafka_broker.config_file}}"
line: "inter.broker.protocol.version={{inter_broker_protocol_version}}"
regexp: inter.broker.protocol.version.*
state: present
notify:
- Restart Kafka
- Wait for URP