Skip to content

fix(elasticsearch): respect user-supplied elasticsearch_cluster_set_up#147

Merged
Oddly merged 1 commit into
mainfrom
fix/respect-user-cluster-set-up
May 7, 2026
Merged

fix(elasticsearch): respect user-supplied elasticsearch_cluster_set_up#147
Oddly merged 1 commit into
mainfrom
fix/respect-user-cluster-set-up

Conversation

@Oddly

@Oddly Oddly commented May 7, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #146.

The elasticsearch role overwrites elasticsearch_cluster_set_up unconditionally via set_fact based on a per-node marker file. When a fresh node joins an existing multi-node cluster, the marker file doesn't exist, so the variable is forced to false even if the user explicitly set it true in inventory. The template then emits cluster.initial_master_nodes, and the new node bootstraps its own single-node cluster instead of joining.

This PR makes the auto-detect set_fact only run when the user has not defined the variable themselves. Existing behaviour for users who don't set the variable is unchanged — the marker file is still consulted on first deploy.

Change

Two set_fact tasks (one for true, one for false) collapsed into a single conditional task:

- name: Set var that cluster is set up (auto-detect via marker file)
  ansible.builtin.set_fact:
    elasticsearch_cluster_set_up: \"{{ elasticsearch_cluster_setup_check.stat.exists | default(false) | bool }}\"
  when: elasticsearch_cluster_set_up is not defined

The second set_fact later in main.yml (after security setup, line ~580 — referencing #137) is unchanged: that one explicitly marks the cluster as set up after this node finishes its security configuration, which is correct behaviour for both new-cluster and join-existing-cluster paths.

Test plan

  • Verified manually: a fresh node with elasticsearch_cluster_set_up: true in inventory now correctly omits cluster.initial_master_nodes from the rendered config and joins the existing cluster
  • Existing molecule scenarios should still pass (no behaviour change for users who don't set the variable)

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced Elasticsearch cluster configuration to respect user-defined settings while maintaining automatic setup detection when no custom configuration is provided.

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
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7292c05e-e96c-4dda-a5f1-bcc2fd8260f0

📥 Commits

Reviewing files that changed from the base of the PR and between 3148986 and 38aaa7e.

📒 Files selected for processing (1)
  • roles/elasticsearch/tasks/main.yml

📝 Walkthrough

Walkthrough

The pull request modifies the elasticsearch role to respect user-supplied elasticsearch_cluster_set_up values. Previously, the role unconditionally overwrote this variable based on a local marker file check. Now it only auto-derives the variable when the user has not already defined it, preserving explicit user configuration while maintaining backward compatibility for existing deployments.

Changes

Elasticsearch Cluster Setup Detection

Layer / File(s) Summary
Initialization Marker Check
roles/elasticsearch/tasks/main.yml
Stat task probes for the elasticsearch_initialized_file marker to check if the node has been deployed before.
Conditional Variable Setup
roles/elasticsearch/tasks/main.yml
Single set_fact task replaces two-branch logic to derive elasticsearch_cluster_set_up from marker file existence only when the variable is not already user-defined.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main fix: respecting user-supplied elasticsearch_cluster_set_up values, which is the primary objective of the changeset.
Linked Issues check ✅ Passed The PR implements the fix proposed in issue #146 (option 1): skipping auto-detection of elasticsearch_cluster_set_up when the user has already defined it, preserving existing auto-detection behavior for undefined cases.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing issue #146; the modification consolidates two set_fact tasks into one conditional task that respects user-supplied values without introducing unrelated alterations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/respect-user-cluster-set-up

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Oddly Oddly added the ci:run Trigger gated pull request CI label May 7, 2026
@github-actions github-actions Bot removed the ci:run Trigger gated pull request CI label May 7, 2026
@Oddly Oddly merged commit 5815640 into main May 7, 2026
52 checks passed
@Oddly Oddly deleted the fix/respect-user-cluster-set-up branch May 7, 2026 17:58
Oddly added a commit that referenced this pull request May 7, 2026
…cluster (#149)

Two checks in the elasticsearch role assume a fresh cluster bootstrap and
fail when a node is added to an existing cluster:

1. Master-count check (tasks/main.yml) requires an odd count of master
   nodes among `ansible_play_hosts_all`. When joining one or two new
   masters at a time, the limited play has 1-2 master-eligible hosts and
   the check fires even though the existing cluster already has its own
   quorum.

2. Runtime cluster setup block (tasks/elasticsearch-security.yml) tries
   the bootstrap password against the ES API, intending to seed elastic
   user, built-in user passwords, etc. On a node joining an existing
   cluster the elastic user already has its real password (replicated
   via cluster state), so bootstrap auth fails and the block aborts
   with: "Bootstrap password authentication failed and this is not the
   CA host".

Both fixes gate the relevant tasks on `elasticsearch_cluster_set_up`,
consistent with the pattern from #146/#147: when the user signals that
the cluster is already bootstrapped, do not run bootstrap-only logic.

Closes #148

Co-authored-by: Sam Crauwels <scrauwels@rinis.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

elasticsearch role overrides user-set elasticsearch_cluster_set_up via local marker-file check, breaking joins to existing clusters

1 participant