From 3116f464226d676cae9603503c3f8a2d57bcf055 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Beno=C3=AEt=20Knecht?= Date: Mon, 1 Jun 2020 17:09:18 +0200 Subject: [PATCH] ceph-rgw-loadbalancer: Fix keepalived master selection MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit While 2ca33641 fixed a bug in the way the `keepalived.conf.j2` template matched hostnames to set the VRRP `MASTER`/`BACKUP` states, it also introduced a regression in the case where `virtual_ips` is a list of more than one IP address. The previous behavior would result in each host in the `rgwloadbalancers` group to be `MASTER` for one of the `virtual_ips`, but the new behavior caused the first host to be `MASTER` for all the IP address in `virtual_ips`. This commit restores the original behavior. Signed-off-by: Benoît Knecht --- roles/ceph-rgw-loadbalancer/tasks/pre_requisite.yml | 2 +- roles/ceph-rgw-loadbalancer/templates/keepalived.conf.j2 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/ceph-rgw-loadbalancer/tasks/pre_requisite.yml b/roles/ceph-rgw-loadbalancer/tasks/pre_requisite.yml index 0a5ffd1eb..0d6d87aa4 100644 --- a/roles/ceph-rgw-loadbalancer/tasks/pre_requisite.yml +++ b/roles/ceph-rgw-loadbalancer/tasks/pre_requisite.yml @@ -19,7 +19,7 @@ - name: set_fact vip to vrrp_instance set_fact: - vrrp_instances: "{{ vrrp_instances | default([]) | union([{ 'name': 'VI_' + index|string , 'vip': item }]) }}" + vrrp_instances: "{{ vrrp_instances | default([]) | union([{ 'name': 'VI_' + index|string , 'vip': item, 'master': groups[rgwloadbalancer_group_name][index] }]) }}" loop: "{{ virtual_ips | flatten(levels=1) }}" loop_control: index_var: index diff --git a/roles/ceph-rgw-loadbalancer/templates/keepalived.conf.j2 b/roles/ceph-rgw-loadbalancer/templates/keepalived.conf.j2 index 8beb0d44c..0c9378d3b 100644 --- a/roles/ceph-rgw-loadbalancer/templates/keepalived.conf.j2 +++ b/roles/ceph-rgw-loadbalancer/templates/keepalived.conf.j2 @@ -15,8 +15,8 @@ vrrp_script check_haproxy { {% for instance in vrrp_instances %} vrrp_instance {{ instance['name'] }} { - state {{ 'MASTER' if inventory_hostname == groups[rgwloadbalancer_group_name][0] else 'BACKUP' }} - priority {{ '100' if inventory_hostname == groups[rgwloadbalancer_group_name][0] else '90' }} + state {{ 'MASTER' if inventory_hostname == instance['master'] else 'BACKUP' }} + priority {{ '100' if inventory_hostname == instance['master'] else '90' }} interface {{ virtual_ip_interface }} virtual_router_id {{ 50 + loop.index }} advert_int 1 -- 2.39.5