3c698f2426
Previously, the number of masters was equal to the node count divided by two and rounded up if an even number. This worked for cluster sizes greater than 3 nodes but did not properly assign enough masters for a 3 node cluster, and did not handle special cases of single node clusters that may exist in a test environment. New code handles these edge cases and improves the comments around node role assignment. Correcting the number of masters has the side effect of also correcting the layout of data nodes. A 3 node cluster will no longer exhibit an unused node. Change-Id: I2243a6c0163ab32e3c0def383a10244a34450530
91 lines
3.4 KiB
YAML
91 lines
3.4 KiB
YAML
---
|
|
|
|
# storage node count is equal to the cluster size
|
|
- name: Node count fact
|
|
set_fact:
|
|
storage_node_count: "{{ groups['elastic-logstash'] | length }}"
|
|
tags:
|
|
- always
|
|
|
|
# the elasticserch cluster elects one master from all those which are marked as master-eligible
|
|
# 1 node cluster can only have one master
|
|
# 2 node clusters have 1 master-eligable nodes to avoid split-brain
|
|
# 3 node clusters have 3 master-eligable nodes
|
|
# >3 node clusters have (nodes // 2) eligable masters rounded up to the next odd number
|
|
- name: Master node count fact
|
|
set_fact:
|
|
master_node_count: |-
|
|
{% set masters = 0 %}
|
|
{% if (storage_node_count | int) < 3 %}
|
|
{% set masters = 1 %}
|
|
{% elif (storage_node_count | int) == 3 %}
|
|
{% set masters = 3 %}
|
|
{% else %}
|
|
{% set masters = (storage_node_count | int ) // 2 %}
|
|
{% if ((masters | int) % 2 == 0) %}
|
|
{% set masters = (masters | int) + 1 %}
|
|
{% endif %}
|
|
{% endif %}
|
|
{{ masters }}
|
|
tags:
|
|
- always
|
|
|
|
# assign node roles
|
|
# the first 'master_node_count' hosts in groups['elastic-logstash'] become master-eligible nodes
|
|
# the first 'master_node_count' and subsequent alternate hosts in groups['elastic-logstash'] becomes data nodes
|
|
- name: Data nodes fact
|
|
set_fact:
|
|
data_nodes: "{{ (groups['elastic-logstash'][:master_node_count | int] + groups['elastic-logstash'][master_node_count | int::2]) }}"
|
|
master_nodes: "{{ groups['elastic-logstash'][:master_node_count | int] }}"
|
|
coordination_nodes: |-
|
|
{% set nodes=[] %}
|
|
{% for host in groups['kibana'] %}
|
|
{% set _ = nodes.insert(loop.index, ((hostvars[host]['ansible_host'] | string) + ":" + (elastic_port | string))) %}
|
|
{% endfor %}
|
|
{{ nodes }}
|
|
zen_nodes: |-
|
|
{% set nodes=[] %}
|
|
{% for host in (groups['elastic-logstash'] | union(groups['kibana'])) %}
|
|
{% set _ = nodes.insert(loop.index, (hostvars[host]['ansible_host'] | string)) %}
|
|
{% endfor %}
|
|
{{ nodes }}
|
|
tags:
|
|
- always
|
|
|
|
# based on the assignment of roles to hosts, set per host booleans
|
|
- name: Node enablement
|
|
set_fact:
|
|
master_node: "{{ (inventory_hostname in master_nodes) | ternary(true, false) }}"
|
|
data_node: "{{ (inventory_hostname in data_nodes) | ternary(true, false) }}"
|
|
tags:
|
|
- always
|
|
|
|
# Set a data node facts. The data nodes, in the case of elasticsearch are also
|
|
# ingest nodes.
|
|
- name: Set data nodes
|
|
set_fact:
|
|
elasticsearch_data_hosts: |-
|
|
{% if inventory_hostname in data_nodes %}
|
|
{% set data_hosts = ['127.0.0.1:' + (elastic_port | string)] %}
|
|
{% else %}
|
|
{% set nodes=[] %}
|
|
{% for host in data_nodes %}
|
|
{% set _ = nodes.insert(loop.index, ((hostvars[host]['ansible_host'] | string) + ":" + (elastic_port | string))) %}
|
|
{% endfor %}
|
|
{% set data_hosts = nodes | shuffle(seed=inventory_hostname) %}
|
|
{% endif %}
|
|
{{ data_hosts }}
|
|
logstash_data_hosts: |-
|
|
{% if inventory_hostname in data_nodes %}
|
|
{% set data_hosts = ['127.0.0.1:' + (logstash_beat_input_port | string)] %}
|
|
{% else %}
|
|
{% set nodes=[] %}
|
|
{% for host in data_nodes %}
|
|
{% set _ = nodes.insert(loop.index, ((hostvars[host]['ansible_host'] | string) + ":" + (logstash_beat_input_port | string))) %}
|
|
{% endfor %}
|
|
{% set data_hosts = nodes | shuffle(seed=inventory_hostname) %}
|
|
{% endif %}
|
|
{{ data_hosts }}
|
|
tags:
|
|
- always
|