Prevent duplicate initial_master_nodes

Elasticsearch fails to start on first run when duplicate entries in the
cluster.initial_master_nodes variable are present, as they are all required
during the initial bootstrapping. It is currently possible for duplicates
to be present in this when nodes are forced to be master-eligible using
elasticsearch_node_master: true
due to the master node setting algorithm within data-node-variables. This
commit ensures that all values within the Ansible master_nodes variable
are unique, whilst keeping the total count of master nodes the same,
preventing Elasticsearch from crashing during initial cluster discovery.

Change-Id: I3763b22ea47c9b5b0f534793ccc6a887f96dc649
This commit is contained in:
Duncan Martin Walker 2020-05-28 14:00:56 +01:00
parent 0a7e1e2a90
commit 8539314a7a

View File

@ -64,19 +64,19 @@ master_nodes: |-
{% set nodes = [] %}
{% for node in groups['elastic'] %}
{% if (nodes | length) <= (elastic_master_node_count | int) %}
{% if (hostvars[node]['elasticsearch_node_master'] is defined) and (hostvars[node]['elasticsearch_node_master'] | bool) %}
{% if (hostvars[node]['elasticsearch_node_master'] is defined) and (hostvars[node]['elasticsearch_node_master'] | bool) and (node not in nodes) %}
{% set _ = nodes.append(node) %}
{% endif %}
{% endif %}
{% endfor %}
{% for node in groups['elastic'] %}
{% if (nodes | length) <= (elastic_master_node_count | int) %}
{% if (node in _master_nodes) %}
{% if (node in _master_nodes) and (node not in nodes) %}
{% set _ = nodes.append(node) %}
{% endif %}
{% endif %}
{% endfor %}
{{ nodes }}
{{ nodes | unique }}
master_node_count: "{{ master_nodes | length }}"
coordination_nodes: |-