From 38aaa7e918e48d43a691ce380ea768cf86e166b8 Mon Sep 17 00:00:00 2001 From: Sam Crauwels Date: Thu, 7 May 2026 17:10:14 +0200 Subject: [PATCH] fix(elasticsearch): respect user-supplied elasticsearch_cluster_set_up The role used to overwrite elasticsearch_cluster_set_up unconditionally via set_fact based on the existence of a per-node marker file (elasticsearch_initialized_file). On a fresh node intended to join an existing multi-node cluster the marker file does not exist, so the variable was forced to false even when the user explicitly set it to true in inventory. The template then emits cluster.initial_master_nodes and the new node bootstraps its own single-node cluster instead of joining. Now the auto-detect set_fact only runs when the user has not defined the variable themselves. Existing behaviour (auto-detection on first deploy) is unchanged for users who do not set the variable. Closes #146 --- roles/elasticsearch/tasks/main.yml | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/roles/elasticsearch/tasks/main.yml b/roles/elasticsearch/tasks/main.yml index 9d55942..a59ba41 100644 --- a/roles/elasticsearch/tasks/main.yml +++ b/roles/elasticsearch/tasks/main.yml @@ -76,19 +76,15 @@ register: elasticsearch_cluster_setup_check failed_when: false -- name: Set var that cluster is set up +# Respect a user-supplied elasticsearch_cluster_set_up value (e.g. when joining +# an existing multi-node cluster from a fresh node, the local marker file does +# not exist but the user knows the cluster is already bootstrapped). Only +# auto-detect via the marker file when the user has not set the variable. +# See https://github.com/Oddly/elasticstack/issues/146 for context. +- name: Set var that cluster is set up (auto-detect via marker file) ansible.builtin.set_fact: - elasticsearch_cluster_set_up: true - when: - - elasticsearch_cluster_setup_check is defined - - elasticsearch_cluster_setup_check.stat.exists | bool - -- name: Set var that cluster is not set up - ansible.builtin.set_fact: - elasticsearch_cluster_set_up: false - when: - - elasticsearch_cluster_setup_check is undefined or - not elasticsearch_cluster_setup_check.stat.exists | bool + elasticsearch_cluster_set_up: "{{ elasticsearch_cluster_setup_check.stat.exists | default(false) | bool }}" + when: elasticsearch_cluster_set_up is not defined - name: Check if master node count is correct when: