Skip to content

fix(elasticsearch): make cluster-settings robust to per-block check_mode - #183

Merged
Oddly merged 1 commit into
mainfrom
fix/elasticsearch-cluster-settings-check-mode
Aug 6, 2026
Merged

fix(elasticsearch): make cluster-settings robust to per-block check_mode#183
Oddly merged 1 commit into
mainfrom
fix/elasticsearch-cluster-settings-check-mode

Conversation

@Oddly

@Oddly Oddly commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Follow-up to #182. Re-including the ES role with check_mode: true on an outer block (which is what elasticsearch_no-security did to cover the guards #154 added) crashed on line 30 of elasticsearch-cluster-settings.yml:

'dict object' has no attribute 'json'

Root cause: ansible_check_mode is the play-level check-mode flag; setting check_mode: true on a block does not flip it, but the uri module still honours the inherited override and returns without an HTTP body. The block-level when: not ansible_check_mode guard then lets execution through anyway, and the next task dereferences _elasticsearch_current_cluster_settings.json which is not there.

Two guards, belt and suspenders:

  • check_mode: false on the GET so a per-block override still runs the request. It's a pure read against /_cluster/settings, safe to always execute.
  • default({}) around .persistent so the compare survives any other reason the response is missing.

Also re-adds the check-mode play to elasticsearch_no-security/converge.yml so the two not ansible_check_mode guards #154 added to Start Elasticsearch and Handle cluster setup without security actually stay covered. That was the piece dropped from #182 because it kept tripping on this bug.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed cluster settings checks so they run reliably in check mode.
    • Improved handling when cluster responses or persistent settings are empty or unavailable.
  • Tests

    • Added regression coverage for including the Elasticsearch role during check-mode validation.
    • Ensured validation uses the same security, release, logging, heap, and group settings as standard deployment checks.

Follow-up to #182. Re-including the role with check_mode: true on an
outer block (as elasticsearch_no-security did to cover the guards
#154 added) crashed on line 30 of elasticsearch-cluster-settings.yml
with:

  'dict object' has no attribute 'json'

Root cause: ansible_check_mode is the PLAY-level check-mode flag;
setting check_mode: true on a block does not flip it, but the uri
module still honours the inherited override and returns without an
HTTP body. The block-level 'when: not ansible_check_mode' guard then
lets execution through anyway, and the next task dereferences
_elasticsearch_current_cluster_settings.json which is missing.

Two guards:
  - check_mode: false on the GET so a per-block override still runs
    the request (this is a pure read, safe to always execute)
  - default({}) around .persistent so the compare survives any
    other reason the response is missing

Also re-adds the check-mode play to elasticsearch_no-security so the
#154 guards actually stay covered.
@Oddly Oddly added the ci:run Trigger gated pull request CI label Aug 6, 2026
@Oddly
Oddly enabled auto-merge (squash) August 6, 2026 11:00
@github-actions github-actions Bot removed the ci:run Trigger gated pull request CI label Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0d951d9a-1c9e-467b-a2d4-79bb33681458

📥 Commits

Reviewing files that changed from the base of the PR and between 61a59ae and 8d6affb.

📒 Files selected for processing (2)
  • molecule/elasticsearch_no-security/converge.yml
  • roles/elasticsearch/tasks/elasticsearch-cluster-settings.yml

📝 Walkthrough

Walkthrough

The PR updates Elasticsearch cluster-settings reads for check mode and missing response data. It also adds Molecule coverage for re-including the Elasticsearch role in check mode.

Changes

Elasticsearch check-mode handling

Layer / File(s) Summary
Cluster-settings read handling
roles/elasticsearch/tasks/elasticsearch-cluster-settings.yml
The cluster-settings request forces check_mode: false. Missing response JSON and persistent settings default to empty mappings.
Check-mode regression coverage
molecule/elasticsearch_no-security/converge.yml
The converge play resets _elasticstack_role_imported and re-includes the Elasticsearch role inside a check_mode: true block. The existing role variables remain in use.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/elasticsearch-cluster-settings-check-mode

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.

@Oddly
Oddly merged commit b15c39a into main Aug 6, 2026
14 of 15 checks passed
@Oddly
Oddly deleted the fix/elasticsearch-cluster-settings-check-mode branch August 6, 2026 11:00
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.

1 participant