# ssh retry functionality (for flaky network responses)

**URL:** <https://forum.ansible.com/t/ssh-retry-functionality-for-flaky-network-responses/22164>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [July 29, 2016, 4:49pm UTC](https://forum.ansible.com/t/ssh-retry-functionality-for-flaky-network-responses/22164 "2016-07-29T16:49:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Richards](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jeff\_Richards](https://forum.ansible.com/u/Jeff_Richards)\
**Post date:** [July 29, 2016, 4:49pm UTC](https://forum.ansible.com/t/ssh-retry-functionality-for-flaky-network-responses/22164/1 "2016-07-29T16:49:17Z")

</div>

Hi,

Is there any way, in Ansible 1.9.6, of having Ansible retry a failed connection attempt x times at y intervals? We are seeing flaky network behavior when deploying on AWS, with apparently random ssh failures causing runs to break.

It’s never in the same place twice so it would be nice if we could have Ansible back off and retry before bailing.

If not in 1.9.6 (which we’re stuck on for another few months … .OpenShift reasons), how about 2.x?

Jeff

---

<div class="post-metadata">

**Author:** ![Ryan\_Groten](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Ryan\_Groten](https://forum.ansible.com/u/Ryan_Groten)\
**Post date:** [August 3, 2016, 3:58pm UTC](https://forum.ansible.com/t/ssh-retry-functionality-for-flaky-network-responses/22164/2 "2016-08-03T15:58:33Z")

</div>

I’ve had moderate success by changing the ControlPersist in ssh\_args parameter in ansible.cfg:

`ssh_args = -o ControlMaster=auto -o ControlPersist=300s`

That said, on big playbooks with a couple hundred hosts/tasks I generally still have at least one or two generic connection failures. Like you it happens on different tasks/hosts every time for me.

---

<div class="post-metadata">

**Author:** ![jeder](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@jeder](https://forum.ansible.com/u/jeder)\
**Post date:** [August 3, 2016, 4:35pm UTC](https://forum.ansible.com/t/ssh-retry-functionality-for-flaky-network-responses/22164/3 "2016-08-03T16:35:42Z")

</div>

A generic retry would be phenomenal. Right now on the openshift side, we’ve found success with this config:

```auto
# config file for ansible -- [http://ansible.com/](http://ansible.com/)
# ==============================================
[defaults]
forks = NNN
host_key_checking = False
remote_user = root
roles_path = roles/
gathering = smart
fact_caching = jsonfile
fact_caching_connection = $HOME/ansible/facts
fact_caching_timeout = 600
log_path = $HOME/ansible.log
nocows = 1
callback_whitelist = profile_tasks

[privilege_escalation]
become = True

[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=600s
control_path = %(directory)s/%%h-%%r
pipelining = True
timeout = 10

```

We give the ansible host as much memory as we possibly can (often 64G or so) for very large deployments where we want a lot of parallelism.

---

<div class="post-metadata">

**Author:** ![Jeff\_Richards](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jeff\_Richards](https://forum.ansible.com/u/Jeff_Richards)\
**Post date:** [August 3, 2016, 7:54pm UTC](https://forum.ansible.com/t/ssh-retry-functionality-for-flaky-network-responses/22164/4 "2016-08-03T19:54:47Z")

</div>

Thanks Ryan, I’ll take a look at that parameter.

Jeff

---

<div class="post-metadata">

**Author:** ![Jeff\_Richards](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jeff\_Richards](https://forum.ansible.com/u/Jeff_Richards)\
**Post date:** [August 3, 2016, 7:55pm UTC](https://forum.ansible.com/t/ssh-retry-functionality-for-flaky-network-responses/22164/5 "2016-08-03T19:55:58Z")

</div>

Thanks Jeremy, will compare and contrast with what we have currently.

If it goes away for more than a week, I’ll holler 🙂

Jeff
