Discovery.zen.minimum_master_nodes templated by Ansible

I am using Ansible to configure the ELK cluster and this includes templating of the elasticsearch.yml configuration file. I want to make discovery.zen.minimum_master_nodes key dependent on the master-eligible nodes in the cluster, to set this value to be a quorum. Given that my master-eligible nodes are members of the "elasticsearch_master" inventory group I came up with this idea:

discovery.zen.minimum_master_nodes: "{{ ((groups['elasticsearch_master']|length) / 2 +1) | round(0, 'ceil') | int}}"

It works but was wondering if there is a better way of doing this, maybe someone more clever figured that out already? Thanks!

I think your formula doesn't work if there's an even number of masters.

It's pretty tricky to design an orchestrator to manipulate this setting correctly. You must get it right in the config file, but you must also increase it through the API before adding more master nodes and/or decrease it after removing them. Frankly it's a pain to do this, which is why we've removed it in 7.x. The simplest answer is to upgrade and then you needn't worry any more.

Of course it won't work because I ate "+1". Corrected now.

Also, when you say you removed it in 7.x, how is that setting now dealt with?

In 7.x you just have to identify the master nodes to use in the first election, and from then on Elasticsearch takes care of adjusting everything as you add or remove nodes.

Eventually, I did the templating like this:

"{{ ((groups['elasticsearch_master']) | length) // 2) + 1 }}"

The "//" division guarantees we do not end up with non-integers.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.