ANSIBLE_SSH_RETRIES on a playbook / host level?

Is it possible to set “retries” or ANSIBLE_SSH_RETRIES on a per host or per play level?

Or is it possible to use Ansible environment variables in AAP somehow? (not setting them as global job setting)?

Context: We are managing many hosts with many roles. Whenever a single host has a brief network connection outage, the whole play and thus all subsequent roles abort for this particular host. We know it’s only a brief outage most of the time, so simply retrying the task that failed the ssh connection would be the simplest solution.

There is “ignore_unreachable”, but this would then skip the failed task and not retry it.

Sure, it would be more ideal to fix the network issue or maybe put an execution node local to the respective hosts location, but this is not an option atm.

You can configure the ansible.builtin.ssh plugin’s reconnection_retries option using the variable ansible_ssh_retries.

1 Like