From 37bce2d21adce6ab2ac90234a356682469d1d45b Mon Sep 17 00:00:00 2001
From: Vitaliy Kukharik <vitabaks@gmail.com>
Date: Mon, 20 Nov 2023 12:52:10 +0300
Subject: [PATCH 1/3] Add "keepalived_virtual_router_id" variable

---
 roles/keepalived/templates/keepalived.conf.j2 | 2 +-
 vars/main.yml                                 | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/roles/keepalived/templates/keepalived.conf.j2 b/roles/keepalived/templates/keepalived.conf.j2
index 4deff2c89..c17a9c3e6 100644
--- a/roles/keepalived/templates/keepalived.conf.j2
+++ b/roles/keepalived/templates/keepalived.conf.j2
@@ -12,7 +12,7 @@ vrrp_script haproxy_check {
  
 vrrp_instance VI_1 {
    interface {{ vip_interface }}
-   virtual_router_id {{ cluster_vip.split('.')[3] | int }}
+   virtual_router_id {{ keepalived_virtual_router_id | default(123) }}
    priority  100
    advert_int 2
    state  BACKUP
diff --git a/vars/main.yml b/vars/main.yml
index 0e150e6da..abdf3a21e 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -42,6 +42,9 @@ haproxy_timeout:
   client: "60m"
   server: "60m"
 
+# keepalived
+keepalived_virtual_router_id: "{{ cluster_vip.split('.')[3] | int }}" # The last octet of 'cluster_vip' IP address is used by default. Must be unique in the network (available values are 0..255).
+
 # vip-manager (if cluster_vip is specified and with_haproxy_load_balancing: false)
 vip_manager_version: "2.1.0"  # version to install
 vip_manager_conf: "/etc/patroni/vip-manager.yml"

From cb2ac46b4584c6f275a6b4535185b2b9b962859c Mon Sep 17 00:00:00 2001
From: Vitaliy Kukharik <vitabaks@gmail.com>
Date: Mon, 20 Nov 2023 12:56:16 +0300
Subject: [PATCH 2/3] fix yamllint warning

---
 vars/main.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/vars/main.yml b/vars/main.yml
index abdf3a21e..301c70510 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -43,7 +43,8 @@ haproxy_timeout:
   server: "60m"
 
 # keepalived
-keepalived_virtual_router_id: "{{ cluster_vip.split('.')[3] | int }}" # The last octet of 'cluster_vip' IP address is used by default. Must be unique in the network (available values are 0..255).
+keepalived_virtual_router_id: "{{ cluster_vip.split('.')[3] | int }}" # The last octet of 'cluster_vip' IP address is used by default.
+# virtual_router_id - must be unique in the network (available values are 0..255).
 
 # vip-manager (if cluster_vip is specified and with_haproxy_load_balancing: false)
 vip_manager_version: "2.1.0"  # version to install

From 1082e310806e9cae5a1ddd690f451aff0d9c0577 Mon Sep 17 00:00:00 2001
From: Vitaliy Kukharik <vitabaks@gmail.com>
Date: Tue, 21 Nov 2023 12:27:02 +0300
Subject: [PATCH 3/3] Update main.yml

---
 vars/main.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/vars/main.yml b/vars/main.yml
index 301c70510..6ed612d95 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -42,11 +42,11 @@ haproxy_timeout:
   client: "60m"
   server: "60m"
 
-# keepalived
+# keepalived (if 'cluster_vip' is specified and 'with_haproxy_load_balancing' is 'true')
 keepalived_virtual_router_id: "{{ cluster_vip.split('.')[3] | int }}" # The last octet of 'cluster_vip' IP address is used by default.
 # virtual_router_id - must be unique in the network (available values are 0..255).
 
-# vip-manager (if cluster_vip is specified and with_haproxy_load_balancing: false)
+# vip-manager (if 'cluster_vip' is specified and 'with_haproxy_load_balancing' is 'false')
 vip_manager_version: "2.1.0"  # version to install
 vip_manager_conf: "/etc/patroni/vip-manager.yml"
 vip_manager_interval: "1000"  # time (in milliseconds) after which vip-manager wakes up and checks if it needs to register or release ip addresses.