Guard URI retry loops against missing .json attribute#57
Merged
Conversation
0890d01 to
ce511d8
Compare
When the ansible.builtin.uri module returns an error response (connection
refused, 401, 503, etc.), the registered variable has no .json attribute.
Accessing .json.status or .json.cluster_name directly in an until condition
then crashes the retry loop with "dict object has no attribute 'json'" instead
of retrying as intended.
Wrap all .json accesses in until conditions with | default({}) so the outer
attribute lookup returns an empty dict on error, allowing the existing
| default('') or | default(false) guards to handle the missing inner key
gracefully and let the retry loop continue.
Fixes #52
ce511d8 to
7f20fd2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the URI module returns an error response (connection refused, 401, 503, etc.), the registered variable has no
.jsonattribute. Theuntilcondition then crashes withdict object has no attribute 'json'instead of retrying, which is the whole point of the retry loop.This wraps all
.jsonaccesses inuntilconditions with| default({})so the outer attribute lookup returns an empty dict on error responses. The existing| default('')or| default(false)guards on the inner key then do their job and the retry loop continues as expected.Affected files:
elasticsearch-security.yml— 4untilconditions (API availability checks, cluster status checks)elasticsearch-rolling-upgrade.yml— 5untilconditions (shard allocation acknowledged, cluster health)main.yml— 1untilcondition (cluster status without security)Fixes #52