# urgent, please help: any way to get ansible to work over an unstable connection?

**URL:** <https://forum.ansible.com/t/urgent-please-help-any-way-to-get-ansible-to-work-over-an-unstable-connection/21359>\
**Category:** Ansible Project\
**Created:** [May 5, 2016, 6:21am UTC](https://forum.ansible.com/t/urgent-please-help-any-way-to-get-ansible-to-work-over-an-unstable-connection/21359 "2016-05-05T06:21:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nrser](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nrser](https://forum.ansible.com/u/nrser)\
**Post date:** [May 5, 2016, 6:21am UTC](https://forum.ansible.com/t/urgent-please-help-any-way-to-get-ansible-to-work-over-an-unstable-connection/21359/1 "2016-05-05T06:21:04Z")

</div>

this is preventing me from deploying so it’s kind of a serious and time-sensitive issue…

i’m in China and the internet connection out of the country (to where our servers are) is unstable.

i’ve been trying to run a playbook with around 12 tasks for an hour or two now, and the whole thing fails seemingly if it can’t connect once:

`UNREACHABLE! => {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}`

it looks like ansible is creating a new ssh connection for _each play_:

`  
ESTABLISH SSH CONNECTION FOR USER: root

SSH: EXEC ssh -C -vvv -o ServerAliveInterval=1 -o KbdInteractiveAuthentication=no …

`

before each task, and it seems to give up completely if it fails to open a connection at any time. this makes it essentially impossible to get through the playbook.

i can hold an ssh terminal open with the server no problem… what’s going on here? is ansible creating a new connection for every task? can i make it just hold one connection open and use that? can i make it retry a few times if it can’t connect?

thanks in advance, Neil.

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 6, 2016, 7:44am UTC](https://forum.ansible.com/t/urgent-please-help-any-way-to-get-ansible-to-work-over-an-unstable-connection/21359/2 "2016-05-06T07:44:26Z")

</div>

Just an idea: SSH to the server, start screen and then apply the  
playbook with target localhost.

I think ansible is using connection multiplexing to avoid having to  
open new connections for each task. Why it does not work in your case?  
No idea.

Johannes

---

<div class="post-metadata">

**Author:** ![nrser](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nrser](https://forum.ansible.com/u/nrser)\
**Post date:** [May 6, 2016, 7:59am UTC](https://forum.ansible.com/t/urgent-please-help-any-way-to-get-ansible-to-work-over-an-unstable-connection/21359/3 "2016-05-06T07:59:50Z")

</div>

that is basically what i ended up doing. it makes the workflow a pain in the ass because i have to make changes to the playbooks on my local machine (connection is too slow and unstable to do much editing on the server), commit, push, and pull on the server, but then running locally works just fine.

whether it’s reusing connections or not, the main issue seems to be that it fails very easily if the connection shakes or dies. the value of software like ansible in my opinion is the declarative nature (this should be in the state), which makes the playbooks idempotent and allows for reties.

---

<div class="post-metadata">

**Author:** ![dch](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dch/32/7132_2.png) [@dch](https://forum.ansible.com/u/dch)\
**Post date:** [May 6, 2016, 8:02am UTC](https://forum.ansible.com/t/urgent-please-help-any-way-to-get-ansible-to-work-over-an-unstable-connection/21359/4 "2016-05-06T08:02:44Z")

</div>

mosh [http://mosh.mit.edu/](http://mosh.mit.edu/) is an excellent replacement for the ssh  
connection from your workstation to the server, to enable editing in  
situ. It uses udp and a predictive transfer mode so works very well over  
sluggish connections. I don't think it would be suitable as a  
replacement for ssh within ansible however, but it might cut down your  
editing hops at least.

A+  
Dave

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 6, 2016, 2:00pm UTC](https://forum.ansible.com/t/urgent-please-help-any-way-to-get-ansible-to-work-over-an-unstable-connection/21359/5 "2016-05-06T14:00:48Z")

</div>

I’ve been toying with a ‘mosh connection plugin’ but that is still in vaporware stage.

For cases like these you might want to look into ansible-pull which will only require an initial access to the ‘git server’ from the machines and then all the tasks run locally, making it much more resilient when connectivity is an issue.

---

<div class="post-metadata">

**Author:** ![nrser](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nrser](https://forum.ansible.com/u/nrser)\
**Post date:** [June 11, 2016, 3:54am UTC](https://forum.ansible.com/t/urgent-please-help-any-way-to-get-ansible-to-work-over-an-unstable-connection/21359/6 "2016-06-11T03:54:19Z")

</div>

thanks, i finally got back around to this and am checking out ansible-pull now.

---

<div class="post-metadata">

**Author:** ![Christoph\_Wegener](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@Christoph\_Wegener](https://forum.ansible.com/u/Christoph_Wegener)\
**Post date:** [June 11, 2016, 11:07am UTC](https://forum.ansible.com/t/urgent-please-help-any-way-to-get-ansible-to-work-over-an-unstable-connection/21359/7 "2016-06-11T11:07:53Z")

</div>

Step 1: Set up your Ansible Control Machine outside of the country closer to your target machines.  
Step 2: Learn Tmux or Screen  
Step 3: Run ‘ansible-playbook’ in Tmux or Screen on your new Control Machine.

---

<div class="post-metadata">

**Author:** ![nrser](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nrser](https://forum.ansible.com/u/nrser)\
**Post date:** [June 11, 2016, 11:37am UTC](https://forum.ansible.com/t/urgent-please-help-any-way-to-get-ansible-to-work-over-an-unstable-connection/21359/8 "2016-06-11T11:37:45Z")

</div>

yup, that’s where i’m at. which i pretty much the same place i was at when i admin’d a cluster eight years ago.

i like ansible as a idempotent library for scripting (way better than the shell scripts we used to use), but it was worth a try to be able to fiddle something on my dev machine and run single local command that would take care of all the hosts and ssh’ing and everything and just get the stuff where it needs to be.

maybe in another eight years 😉
