Skip to content

fix(elasticsearch): gate remaining tasks on check mode#154

Open
Oddly wants to merge 1 commit into
mainfrom
fix/check-mode-remaining-gaps
Open

fix(elasticsearch): gate remaining tasks on check mode#154
Oddly wants to merge 1 commit into
mainfrom
fix/check-mode-remaining-gaps

Conversation

@Oddly

@Oddly Oddly commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Two paths in the elasticsearch role still ran (or wasted time) under `--check`.

The no-security cluster setup block in `tasks/main.yml` hit the cluster health API with `ignore_errors: ansible_check_mode`. The `until` loop (30 × 10s) still executed, so a check-mode pass burnt up to five minutes waiting on an endpoint that cannot respond without a running service. Moved the check-mode guard up to the block-level `when` so the whole branch is skipped, and dropped the now-redundant `ignore_errors`.

The handler that restarts Kibana after an Elasticsearch certificate change in `handlers/main.yml` had no check-mode guard, so it would attempt a service restart and HTTP probe against a Kibana that may not even be running. Added the same `not ansible_check_mode` condition the four neighbouring Elasticsearch restart handlers in this file already use.

No molecule scenario currently runs the role under `--check`, so I haven't added a verify-side test — adding a check-mode converge would be more invasive than the fix. The change has no behavioural impact on normal (non-check-mode) runs.

Closes #25.

Summary by CodeRabbit

  • Chores
    • Improved Ansible check mode handling by adding skip conditions to prevent unnecessary operations during validation runs.
    • Enhanced cluster health probing logic to skip execution entirely in check mode, replacing error suppression with conditional gating.

Two paths in the elasticsearch role still attempted runtime operations under --check:

The no-security cluster setup block hit the cluster health API with ignore_errors set to ansible_check_mode. The retry loop (30 × 10s) still ran, so a check-mode pass wasted up to five minutes waiting on an endpoint that cannot be reached without a running service. Moved the check-mode guard to the block-level when so the whole branch is skipped instead.

The handler that restarts Kibana after an Elasticsearch certificate change had no check-mode guard, so it would attempt service restarts and HTTP probes against a Kibana that isn't necessarily up. Added the same not ansible_check_mode condition the other restart handlers in this file already use.

Closes #25.
@coderabbitai

coderabbitai Bot commented Jun 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: 7f090073-8ecf-4821-a02a-e7a0f4485fab

📥 Commits

Reviewing files that changed from the base of the PR and between 76f7a50 and fc608fa.

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

📝 Walkthrough

Walkthrough

This PR improves check mode support for the Elasticsearch Ansible role by adding guards to prevent operations that require a live Elasticsearch instance. The Kibana restart handler and cluster health check task now skip execution during ansible_check_mode instead of failing or using error suppression.

Changes

Check Mode Guards

Layer / File(s) Summary
Add check mode guards to handler and health check
roles/elasticsearch/handlers/main.yml, roles/elasticsearch/tasks/main.yml
Kibana restart handler adds not ansible_check_mode to its when conditions. Cluster health check refactors from running with ignore_errors: "{{ ansible_check_mode }}" to being entirely gated by not ansible_check_mode, preventing execution in check mode when Elasticsearch is unavailable.

🎯 1 (Trivial) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR addresses core requirements from issue #25: adding check-mode guards to handlers and the cluster setup block, though it appears incomplete relative to all targeted files. Verify that all targeted files from issue #25 have been addressed: main.yml, elasticsearch-security.yml, wait_for_instance.yml, and handlers/main.yml. The PR currently only covers handlers/main.yml and main.yml.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(elasticsearch): gate remaining tasks on check mode' clearly and concisely summarizes the main change of adding ansible_check_mode guards to prevent runtime operations during check mode.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective of gating tasks on check mode; no extraneous modifications were introduced.
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/check-mode-remaining-gaps

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.

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.

Improve check mode support for elasticsearch role

1 participant