Modularize keepalived configs

This commit is contained in:
Salt 2021-03-24 17:49:25 -05:00
parent 059802d326
commit d1252592f1
4 changed files with 40 additions and 29 deletions

View File

@ -31,6 +31,7 @@ all:
kubernetes_role: node kubernetes_role: node
hosts: hosts:
pi-kub-node-1.desu.ltd: pi-kub-node-1.desu.ltd:
keepalived_state: MASTER
keepalived_priority: 50 keepalived_priority: 50
pi-kub-node-2.desu.ltd: pi-kub-node-2.desu.ltd:
keepalived_priority: 49 keepalived_priority: 49

View File

@ -28,6 +28,13 @@
roles: roles:
- role: keepalived - role: keepalived
vars: vars:
keepalived_auth_pass: "{{ secret_keepalived_pass }}" keepalived_stanzas:
keepalived_vip: "192.168.102.200/16" - name: VI_1
state: "{{ keepalived_state | default('BACKUP') }}"
interface: eth0
virtual_router_id: 51
priority: "{{ keepalived_priority }}"
advert_int: 1
auth_pass: "{{ secret_keepalived_pass }}"
vip: "192.168.102.200/16"
tags: [ k8s, keepalived ] tags: [ k8s, keepalived ]

View File

@ -1,21 +1,22 @@
# vim:ft=ansible: # vim:ft=ansible:
# Node priority. Should be assigned differently for each host # A list of stanzas to put in the keepalived.conf file
keepalived_priority: 50 keepalived_stanzas: []
# Node state. Should be "MASTER" on the master and "BACKUP" on backup machines #keepalived_stanzas:
keepalived_state: "BACKUP" # # Name of the vrrp instance
# - name: VI_1
# The interface to assign the VIP to # # Node state. Should be "MASTER" on the master and "BACKUP" on backup machines
keepalived_interface: "eth0" # state: BACKUP
# The virtual router ID # # The interface to assign the VIP to
keepailved_virtual_router_id: 51 # interface: eth0
# The VIP to pass around. Include the subnet mask like so: # # The virtual router ID
# 192.168.0.5/24 # virtual_router_id: 51
keepalived_vip: "" # # Node priority. Should be assigned differently for each host
# Advertisement interval in seconds # priority: 100
keepalived_advert_int: 1 # # Advertisement interval in seconds
# Name of the vrrp instance # advert_int: 1
keepalived_vrrp_instance_name: "VI_1" # # Keepalived authentication password
# auth_pass: mySuperSecretPassword
# Keepalived authentication password # # The VIP to pass around. Include the subnet mask like so:
#keepalived_auth_pass # # 192.168.0.5/24
# vip: 1.2.3.4

View File

@ -1,14 +1,16 @@
vrrp_instance {{ keepalived_vrrp_instance_name }} { {% for stanza in keepalived_stanzas %}
state {{ keepalived_state }} vrrp_instance {{ stanza.name }} {
interface {{ keepalived_interface }} state {{ stanza.state | default('BACKUP') }}
virtual_router_id {{ keepailved_virtual_router_id }} interface {{ stanza.interface }}
priority {{ keepalived_priority }} virtual_router_id {{ stanza.virtual_router_id }}
advert_int {{ keepalived_advert_int }} priority {{ stanza.priority }}
advert_int {{ stanza.advert_int | default('1') }}
authentication { authentication {
auth_type PASS auth_type PASS
auth_pass {{ keepalived_auth_pass }} auth_pass {{ stanza.auth_pass }}
} }
virtual_ipaddress { virtual_ipaddress {
{{ keepalived_vip }} {{ stanza.vip }}
} }
} }
{% endfor %}