Skip to content

fix(elasticsearch): scope master count to the current play's hosts#144

Merged
Oddly merged 1 commit intomainfrom
fix/master-count-per-cluster
Apr 23, 2026
Merged

fix(elasticsearch): scope master count to the current play's hosts#144
Oddly merged 1 commit intomainfrom
fix/master-count-per-cluster

Conversation

@Oddly
Copy link
Copy Markdown
Owner

@Oddly Oddly commented Apr 23, 2026

Closes #143.

`group_by` accumulates into the global `groups` map across plays, so when the role runs against two separate clusters in the same `ansible-playbook` invocation (the reported case is a primary cluster plus a monitoring cluster), the second play sees every master-eligible node the run has touched — not just its own. A 3-node primary (odd, passes) followed by a 1-node monitor then trips the odd-count assertion at 4. Fix scopes the count via `ansible_play_hosts_all | intersect(...)` so each play evaluates only its own cluster.

To catch this in CI, extended `molecule/elasticsearch_roles_calculation` with a fourth host in a separate `elasticsearch_mon` group and a second play against that group. The scenario uses `elasticsearch_check_calculation: true` so it exits before installing ES — the added cost is one container, not a second cluster deploy. Without the fix, the second play sees 4 masters and fails; with the fix it sees 1 and passes.

group_by accumulates globally across plays, so when the same role runs in
two back-to-back plays against two distinct clusters (e.g. primary + a
separate monitoring cluster) the second play sees the union of both
clusters' master-eligible nodes. The assertion that asserts an odd master
count then fails — 3 + 1 = 4 is even — even though each cluster on its
own has an odd count.

Scope the count to ansible_play_hosts_all, which is the set of hosts in
the current play, so the assertion reflects the cluster being deployed
rather than every cluster touched in the run.

Extended the elasticsearch_roles_calculation scenario to reproduce this:
a fourth host in a separate elasticsearch_mon group, converged in a
second play within the same run. Without the fix the second play sees
4 masters and fails; with the fix it sees 1.

Closes #143
@Oddly Oddly added the ci:run Trigger gated pull request CI label Apr 23, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

@Oddly has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 27 minutes and 57 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 27 minutes and 57 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 22206f8f-bdd8-45e9-85ef-1d8d78f595c8

📥 Commits

Reviewing files that changed from the base of the PR and between 0e109da and 9fb5fe1.

📒 Files selected for processing (4)
  • molecule/elasticsearch_roles_calculation/converge.yml
  • molecule/elasticsearch_roles_calculation/molecule.yml
  • molecule/elasticsearch_roles_calculation/verify.yml
  • roles/elasticsearch/tasks/main.yml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/master-count-per-cluster

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.

@github-actions github-actions Bot removed the ci:run Trigger gated pull request CI label Apr 23, 2026
@Oddly Oddly merged commit cc69feb into main Apr 23, 2026
54 checks passed
@Oddly Oddly deleted the fix/master-count-per-cluster branch April 23, 2026 15:53
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.

Master node count check conflates separate clusters deployed in same run

1 participant