Stable keepalived priorities
The calculation of the keepalived priority depended on the set of hosts in the ansible_play_hosts variable. This meant that priorites changed when the playbook was limited to only run on a subset of the hosts in the "haproxy" group (eg. when reinstalling just one node). This change replaces ansible_play_hosts by groups["haproxy"] so that the priority calculation is stable as long as the set of haproxy nodes does not change. It also simplifies the priority calculation without changeing the result. This change does not change the configuration in case the playbook is run without --limit and ensures that the configuration does not change if it is run with --limit. To make sure the group vars resolution is not done in a all group, which might have 0 haproxy nodes, we ensure the group vars are applied properly to the haproxy group. This is a partial backport of the patch to limit group_vars scoping [1]. [1]:85501cbf26 (diff-849f58a4930e8d8f73fd8310002552a9)
Co-Authored-By: Jean-Philippe Evrard <jean-philippe@evrard.me> Change-Id: I378351954fbed7b1fc31303c60e4575ddad9cf1d (cherry picked from commit78ed74957d
)
This commit is contained in:
parent
57025d8124
commit
629a9a5cd6
|
@ -40,15 +40,15 @@ keepalived_scripts:
|
||||||
|
|
||||||
# If you have more than 5 keepalived nodes, you should build your own script
|
# If you have more than 5 keepalived nodes, you should build your own script
|
||||||
# (handling master and backups servers), and replace in keepalived_instances:
|
# (handling master and backups servers), and replace in keepalived_instances:
|
||||||
# priority: "{{ ((ansible_play_hosts|length-ansible_play_hosts.index(inventory_hostname))*100)-((ansible_play_hosts|length-ansible_play_hosts.index(inventory_hostname))*50) }}"
|
# priority: "{{ (groups['haproxy']|length-groups['haproxy'].index(inventory_hostname)*50 }}"
|
||||||
# by
|
# by
|
||||||
# priority: "{{ (ansible_play_hosts.index(inventory_hostname) == 0) | ternary('100','50') }}"
|
# priority: "{{ (groups['haproxy'].index(inventory_hostname) == 0) | ternary('100','50') }}"
|
||||||
keepalived_instances:
|
keepalived_instances:
|
||||||
external:
|
external:
|
||||||
interface: "{{ haproxy_keepalived_external_interface | default(management_bridge) }}"
|
interface: "{{ haproxy_keepalived_external_interface | default(management_bridge) }}"
|
||||||
state: "{{ (ansible_play_hosts.index(inventory_hostname) == 0) | ternary('MASTER', 'BACKUP') }}"
|
state: "{{ (groups['haproxy'].index(inventory_hostname) == 0) | ternary('MASTER', 'BACKUP') }}"
|
||||||
virtual_router_id: "{{ haproxy_keepalived_external_virtual_router_id | default ('10') }}"
|
virtual_router_id: "{{ haproxy_keepalived_external_virtual_router_id | default ('10') }}"
|
||||||
priority: "{{ ((ansible_play_hosts|length-ansible_play_hosts.index(inventory_hostname))*100)-((ansible_play_hosts|length-ansible_play_hosts.index(inventory_hostname))*50) }}"
|
priority: "{{ (groups['haproxy']|length-groups['haproxy'].index(inventory_hostname))*50 }}"
|
||||||
authentication_password: "{{ haproxy_keepalived_authentication_password }}"
|
authentication_password: "{{ haproxy_keepalived_authentication_password }}"
|
||||||
vips:
|
vips:
|
||||||
- "{{ haproxy_keepalived_external_vip_cidr | default('169.254.1.1/24') }} dev {{ haproxy_keepalived_external_interface | default(management_bridge) }}"
|
- "{{ haproxy_keepalived_external_vip_cidr | default('169.254.1.1/24') }} dev {{ haproxy_keepalived_external_interface | default(management_bridge) }}"
|
||||||
|
@ -57,9 +57,9 @@ keepalived_instances:
|
||||||
- pingable_check_script
|
- pingable_check_script
|
||||||
internal:
|
internal:
|
||||||
interface: "{{ haproxy_keepalived_internal_interface | default(management_bridge) }}"
|
interface: "{{ haproxy_keepalived_internal_interface | default(management_bridge) }}"
|
||||||
state: "{{ (ansible_play_hosts.index(inventory_hostname) == 0) | ternary('MASTER', 'BACKUP') }}"
|
state: "{{ (groups['haproxy'].index(inventory_hostname) == 0) | ternary('MASTER', 'BACKUP') }}"
|
||||||
virtual_router_id: "{{ haproxy_keepalived_internal_virtual_router_id | default ('11') }}"
|
virtual_router_id: "{{ haproxy_keepalived_internal_virtual_router_id | default ('11') }}"
|
||||||
priority: "{{ ((ansible_play_hosts|length-ansible_play_hosts.index(inventory_hostname))*100)-((ansible_play_hosts|length-ansible_play_hosts.index(inventory_hostname))*50) }}"
|
priority: "{{ (groups['haproxy']|length-groups['haproxy'].index(inventory_hostname))*50 }}"
|
||||||
authentication_password: "{{ haproxy_keepalived_authentication_password }}"
|
authentication_password: "{{ haproxy_keepalived_authentication_password }}"
|
||||||
track_scripts:
|
track_scripts:
|
||||||
- haproxy_check_script
|
- haproxy_check_script
|
Loading…
Reference in New Issue