/
keepalived.conf.j2
314 lines (303 loc) · 10.3 KB
/
keepalived.conf.j2
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#jinja2: lstrip_blocks: True
{#
# Copyright 2015, Jean-Philippe Evrard <jean-philippe@evrard.me>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-#}
{% if keepalived_show_ansible_managed|bool %}
{{ ansible_managed | comment }}
{% endif %}
{% if keepalived_global_defs is defined %}
global_defs {
{% for def in keepalived_global_defs %}
{{ def }}
{% endfor %}
}
{% endif %}
{% if keepalived_scripts is defined %}
{% for name, details in keepalived_scripts.items() %}
vrrp_script {{ name }} {
script "{{ details.check_script }}"
interval {{ details.interval | default(5) }} # checking every {{ details.interval | default(5) }} seconds (default: 5 seconds)
fall {{ details.fall | default(3) }} # require {{ details.fall | default(3) }} failures for KO (default: 3)
rise {{ details.rise | default(6) }} # require {{ details.rise | default(6) }} successes for OK (default: 6)
{% if details.weight is defined %}
weight {{ details.weight | default(0) }} # adjust priority by this weight, (default: 0)
{% endif %}
{% if details.timeout is defined %}
timeout {{ details.timeout }} # allow scripts like ping to succeed, before timing out
{% endif %}
{% if details.user is defined %}
user {{ details.user }} # user/group names to run script under.
{% endif %}
}
{% endfor %}
{% endif %}
{% if keepalived_track_files is defined %}
{% for name, details in keepalived_track_files.items() %}
vrrp_track_file {{ name }} {
file "{{ details.file }}"
weight {{ details.weight | default(1) }} # multiply with weight in file (default: 1, i.e. literal value from file)
{% if details.init_file | default(false) | bool %}
init_file {% if details.init_file_value is defined %}{{ details.init_file_value }}{% endif %}{% if details.init_file_overwrite | default(false) | bool %}overwrite{% endif %}
{% endif %}
}
{% endfor %}
{% endif %}
{% if keepalived_track_processs is defined %}
{% for name, details in keepalived_track_processs.items() %}
vrrp_track_process {{ name }} {
process {{ details.process }} # see man 5 keepalived.conf for quotes handling
weight {{ details.weight | default(1) | int }} # multiply with weight in process (default: 1, i.e. literal value from process)
{% if details.param_match is defined %}
param_match {{ details.param_match }}
{% endif %}
{% if details.quorum is defined %}
quorum {{ details.quorum | int }}
{% endif %}
{% if details.quorum_max is defined %}
quorum_max {{ details.quorum_max | int }}
{% endif %}
{% if details.fork_delay is defined %}
fork_delay {{ details.fork_delay | int }}
{% endif %}
{% if details.terminate_delay is defined %}
terminate_delay {{ details.terminate_delay | int }}
{% endif %}
{% if details.delay is defined %}
delay {{ details.delay | int }}
{% endif %}
{% if details.full_command | default(false) | bool %}
full_command
{% endif %}
}
{% endfor %}
{% endif %}
{% for name, sync_group in keepalived_sync_groups.items() %}
vrrp_sync_group {{ name }} {
group {
{% for instance in sync_group.instances %}
{{ instance }}
{% endfor %}
}
{% if sync_group.notify_script is defined %}
notify "{{ sync_group.notify_script }}"
{% endif %}
{% if sync_group.notify_master is defined %}
notify_master "{{ sync_group.notify_master }}"
{% endif %}
{% if sync_group.notify_backup is defined %}
notify_backup "{{ sync_group.notify_backup }}"
{% endif %}
{% if sync_group.notify_fault is defined %}
notify_fault "{{ sync_group.notify_fault }}"
{% endif %}
{% if sync_group.global_tracking is defined and sync_group.global_tracking | bool %}
global_tracking # All VRRP share the same tracking config.
{% endif %}
{% if sync_group.track_scripts is defined %}
track_script {
{% for track_script in sync_group.track_scripts %}
{{ track_script }}
{% endfor %}
}
{% endif %}
{% if sync_group.track_files is defined %}
track_file {
{% for track_file in sync_group.track_files %}
{{ track_file }}
{% endfor %}
}
{% endif %}
{% if sync_group.track_interfaces is defined %}
track_interface {
{% for track_interface in sync_group.track_interfaces %}
{{ track_interface }}
{% endfor %}
}
{% endif %}
{% if sync_group.track_processs is defined %}
track_process {
{% for track_process in sync_group.track_processs %}
{{ track_process }}
{% endfor %}
}
{% endif %}
}
{% endfor %}
{% for name, instance in keepalived_instances.items() %}
vrrp_instance {{ name }} {
interface {{ instance.interface }}
state {{ instance.state }}
virtual_router_id {{ instance.virtual_router_id }}
priority {{ instance.priority }}
{% if instance.use_vmac is defined and instance.use_vmac | bool %}
use_vmac # Use virtual MAC address
{% endif %}
{% if instance.vmac_xmit_base is defined and instance.vmac_xmit_base | bool %}
vmac_xmit_base # Use physical MAC address for communication
{% endif %}
{% if instance.nopreempt is defined and instance.nopreempt | bool %}
nopreempt # Override VRRP RFC preemption default
{% endif %}
{% if instance.preempt_delay is defined %}
preempt_delay {{ instance.preempt_delay }} # Seconds after startup until preemption. 0 (default) to 1,000.
{% endif %}
{% if instance.advert_int is defined %}
advert_int {{ instance.advert_int }}
{% endif %}
{% if instance.dont_track_primary is defined and instance.dont_track_primary | bool %}
dont_track_primary # Override VRRP RFC dont_track_primary default
{% endif %}
{% if instance.accept is defined %}
{% if instance.accept | bool %}
accept
{% else %}
no_accept
{% endif %}
{% endif %}
{% if instance.native_ipv6 is defined and instance.native_ipv6 | bool %}
native_ipv6
{% endif %}
{% if instance.authentication_password is defined %}
authentication {
auth_type {{ instance.authentication_type | default('PASS') }}
auth_pass {{ instance.authentication_password }}
}
{% endif %}
{% if instance.unicast_src_ip is defined and instance.unicast_peers|length > 0 %}
unicast_src_ip {{ instance.unicast_src_ip }}
unicast_peer {
{% for peer in instance.unicast_peers %}
{{ peer }}
{% endfor %}
}
{% endif %}
{% if instance.vips is defined and instance.vips | length > 0 %}
virtual_ipaddress {
{% for vip in instance.vips %}
{{ vip }}
{% endfor %}
}
{% endif %}
{% if instance.vips_excluded is defined and instance.vips_excluded | length > 0 %}
virtual_ipaddress_excluded {
{% for vip in instance.vips_excluded %}
{{ vip }}
{% endfor %}
}
{% endif %}
{% if instance.virtual_routes is defined %}
virtual_routes {
{% for route in instance.virtual_routes %}
{{ route }}
{% endfor %}
}
{% endif %}
{% if instance.virtual_rules is defined %}
virtual_rules {
{% for rule in instance.virtual_rules %}
{{ rule }}
{% endfor %}
}
{% endif %}
{% if instance.track_scripts is defined %}
track_script {
{% for track_script in instance.track_scripts %}
{{ track_script }}
{% endfor %}
}
{% endif %}
{% if instance.track_files is defined %}
track_file {
{% for track_file in instance.track_files %}
{{ track_file }}
{% endfor %}
}
{% endif %}
{% if instance.track_interfaces is defined %}
track_interface {
{% for track_interface in instance.track_interfaces %}
{{ track_interface }}
{% endfor %}
}
{% endif %}
{% if instance.track_processs is defined %}
track_process {
{% for track_process in instance.track_processs %}
{{ track_process }}
{% endfor %}
}
{% endif %}
{% if instance.notify_script is defined %}
notify "{{ instance.notify_script }}"
{% endif %}
{% if instance.notify_master is defined %}
notify_master "{{ instance.notify_master }}"
{% endif %}
{% if instance.notify_master_rx_lower_pri is defined %}
notify_master_rx_lower_pri "{{ instance.notify_master_rx_lower_pri }}"
{% endif %}
{% if instance.notify_backup is defined %}
notify_backup "{{ instance.notify_backup }}"
{% endif %}
{% if instance.notify_fault is defined %}
notify_fault "{{ instance.notify_fault }}"
{% endif %}
{% if instance.notify_stop is defined %}
notify_stop "{{ instance.notify_stop }}"
{% endif %}
{% if instance.smtp_alert is defined and instance.smtp_alert | bool %}
smtp_alert # Send email notification during state transition
{% endif %}
}
{% endfor %}
{% if keepalived_virtual_servers is defined %}
{% for vserver in keepalived_virtual_servers %}
virtual_server {{ vserver.ip }} {{ vserver.port }} {
{% include './templates/keepalived-virtual-server.j2' %}
{% for rserver in vserver.real_servers %}
real_server {{ rserver.ip }} {{ rserver.port }} {
{% include './templates/keepalived-real-server.j2' %}
{% include './templates/keepalived-checks.j2' %}
}
{% endfor %}
{% if vserver.sorry_server is defined %}
sorry_server {{ vserver.sorry_server.ip }} {{ vserver.sorry_server.port }}
{% endif %}
}
{% endfor %}
{% endif %}
{% if keepalived_virtual_server_groups is defined %}
{% for vserver_group in keepalived_virtual_server_groups %}
virtual_server_group {{ vserver_group.name }} {
{% for vserver_group_vip in vserver_group.vips %}
{{ vserver_group_vip.ip }} {{ vserver_group_vip.port }}
{% endfor %}
{% if vserver_group.fwmark is defined %}
fwmark {{ vserver_group.fwmark }}
{% endif %}
}
virtual_server group {{ vserver_group.name }} {
{# set variable to prevent duplicate code for the same task #}
{% set vserver = vserver_group %}
{% include './templates/keepalived-virtual-server.j2' %}
{% for rserver in vserver_group.real_servers %}
real_server {{ rserver.ip }} {{ rserver.port }} {
{% include './templates/keepalived-real-server.j2' %}
{% include './templates/keepalived-checks.j2' %}
}
{% endfor %}
}
{% endfor %}
{% endif %}