Skip to content

Ansible 2.19 strict conditionals reject dict-literal default() in elasticsearch handlers #139

@Oddly

Description

@Oddly

Summary

With Ansible 2.19 the elasticsearch role handlers in PR #137 fail at runtime with Conditional expressions must be strings.. Ansible 2.19 has tightened conditional evaluation to require pure string expressions, and the dict-literal default({'changed': false}) pattern now triggers this error.

Reproduction

  1. Sync to current main (includes fix(elasticsearch): roll config restarts #137 "fix(elasticsearch): roll config restarts").
  2. Run any playbook that triggers the Restart Elasticsearch handler on Ansible 2.19.x (e.g. a config change that notifies the handler).
  3. Handler fails before it can run.

Error

[ERROR]: Task failed: Conditional expressions must be strings.
Origin: .../collections/oddly/elasticstack/roles/elasticsearch/handlers/main.yml:10:7

 8     - not ansible_check_mode
 9     - elasticsearch_enable | bool
10     - not (_elasticsearch_freshstart | default({'changed': false})).changed | bool
         ^ column 7

Same pattern (8 occurrences across 4 handlers) in roles/elasticsearch/handlers/main.yml:

  • Mark Elasticsearch restart requested
  • Restart Elasticsearch directly
  • and the two follow-up handlers

Suggested fix

Replace the dict-literal default with a default on the attribute:

```diff

    • not (_elasticsearch_freshstart | default({'changed': false})).changed | bool
    • not (_elasticsearch_freshstart_security | default({'changed': false})).changed | bool
    • not (_elasticsearch_freshstart.changed | default(false) | bool)
    • not (_elasticsearch_freshstart_security.changed | default(false) | bool)
      ```

Semantically equivalent: both return `false` (don't block restart) when the fact is undefined or when `.changed` is missing. Avoids dict literals inside the conditional, which the 2.19 evaluator rejects.

Environment

Workaround

Set `ANSIBLE_ALLOW_BROKEN_CONDITIONALS=1` — temporary, not recommended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions