Retry SSH connection setup to fix intermittent publickey errors#2282
Merged
Conversation
Since #2134 the SSH ControlPath directory is unique per task and removed in the finally block, so there is no persistent ControlMaster socket reuse across runs anymore. Every run now cold-establishes the SSH connection to every host. With Ansible's default ANSIBLE_SSH_RETRIES=0 a single transient failure during this cold connection setup makes the affected hosts fail immediately as UNREACHABLE with "Permission denied (publickey)", typically on the very first task that contacts the nodes (e.g. module-load) and for all hosts of the batch at once, while an immediate re-run succeeds. This is a regression of #2134 for the sequential single-playbook case, which previously was masked by persistent ControlMaster socket reuse. Set ANSIBLE_SSH_RETRIES=3 (unless already provided via the environment) right next to the #2134 logic so transient first-contact glitches no longer abort the whole run. AI-assisted: Claude Code Signed-off-by: Christian Berendt <berendt@osism.tech>
Member
Author
|
@janhorstmann Can you check this? Maybe this could resolved the unreachable issues. |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider making the retry count configurable (e.g. via a setting or constant) instead of hardcoding
"3"so that operators can tune behavior without code changes. - It may be useful to log when
ANSIBLE_SSH_RETRIESis being set implicitly so users can understand why retry behavior changed when troubleshooting SSH issues.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider making the retry count configurable (e.g. via a setting or constant) instead of hardcoding `"3"` so that operators can tune behavior without code changes.
- It may be useful to log when `ANSIBLE_SSH_RETRIES` is being set implicitly so users can understand why retry behavior changed when troubleshooting SSH issues.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
The ANSIBLE_SSH_RETRIES value introduced in d808da1 was hardcoded to 3. Expose it as a run_ansible_in_environment(ssh_retries=3) default parameter so callers can override the retry count while keeping the existing behaviour as the default. AI-assisted: Claude Code Signed-off-by: Christian Berendt <berendt@osism.tech>
janhorstmann
approved these changes
May 19, 2026
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.
Since #2134 the SSH ControlPath directory is unique per task and removed in the finally block, so there is no persistent ControlMaster socket reuse across runs anymore. Every run now cold-establishes the SSH connection to every host.
With Ansible's default ANSIBLE_SSH_RETRIES=0 a single transient failure during this cold connection setup makes the affected hosts fail immediately as UNREACHABLE with "Permission denied (publickey)", typically on the very first task that contacts the nodes (e.g. module-load) and for all hosts of the batch at once, while an immediate re-run succeeds. This is a regression of #2134 for the sequential single-playbook case, which previously was masked by persistent ControlMaster socket reuse.
Set ANSIBLE_SSH_RETRIES=3 (unless already provided via the environment) right next to the #2134 logic so transient first-contact glitches no longer abort the whole run.
AI-assisted: Claude Code