# Minimize ssh connections number

**URL:** <https://forum.ansible.com/t/minimize-ssh-connections-number/16547>\
**Category:** Ansible Project\
**Created:** [October 18, 2014, 3:50pm UTC](https://forum.ansible.com/t/minimize-ssh-connections-number/16547 "2014-10-18T15:50:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexey\_Wasilyev1](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@Alexey\_Wasilyev1](https://forum.ansible.com/u/Alexey_Wasilyev1)\
**Post date:** [October 18, 2014, 3:50pm UTC](https://forum.ansible.com/t/minimize-ssh-connections-number/16547/1 "2014-10-18T15:50:22Z")

</div>

Hello, everybody!

I use ansible for everyday production servers maintenance.  
During run, ansible makes a lot of ssh connections to every server, every connection is logged and according to internal policy I have to write a note to the security journal about every ssh connection.  
So, is there any way to minimize number of ssh connections? Say, lets ansible connect to ssh, do all recipes and disconnect instead of doing separate connections for every recipe?

I try to use accelerate=True mode, but it is buggy. Regularly i got “Failed to connect to xx.xx.xx.xx:5099” during ansible run, and i need to manully kill ansible-accelerate daemon to recover node.

Any ideas?

---

<div class="post-metadata">

**Author:** ![Mark\_Phillips](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mark\_Phillips](https://forum.ansible.com/u/Mark_Phillips)\
**Post date:** [October 19, 2014, 6:09pm UTC](https://forum.ansible.com/t/minimize-ssh-connections-number/16547/2 "2014-10-19T18:09:11Z")

</div>

What version of Ansible are you using Alexey? Look at 'pipelining', that's probably what you're after. I think it needs a fairly recent ssh version too though.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 20, 2014, 8:59pm UTC](https://forum.ansible.com/t/minimize-ssh-connections-number/16547/3 "2014-10-20T20:59:06Z")

</div>

ControlPersist is the way to reduce the number of connections.

Also don’t delegate\_to a bunch to the same host.

See

### [Ansible Performance Tuning (for Fun and Profit)](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCAQFjAA&url=http%3A%2F%2Fwww.ansible.com%2Fblog%2Fansible-performance-tuning&ei=kndFVMmmK8_FggSO9IDYCg&usg=AFQjCNHiVWlkQJLWYF0ihfm6cNMT_O2Pzw&bvm=bv.77880786,d.eXY)

---

<div class="post-metadata">

**Author:** ![Alexey\_Wasilyev1](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@Alexey\_Wasilyev1](https://forum.ansible.com/u/Alexey_Wasilyev1)\
**Post date:** [October 22, 2014, 5:46am UTC](https://forum.ansible.com/t/minimize-ssh-connections-number/16547/4 "2014-10-22T05:46:40Z")

</div>

1.7.2, from os x and ubuntu as control node, centos 6.5 as target. pipelining enabled.  
and there are a lot of login records in the target machine /var/log/secure during every ansible run.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 22, 2014, 6:02pm UTC](https://forum.ansible.com/t/minimize-ssh-connections-number/16547/5 "2014-10-22T18:02:06Z")

</div>

pipelining alone won’t do anything without Control Persist, but I’d check to make sure you weren’t using paramiko as the default SSH args do use CP.

---

<div class="post-metadata">

**Author:** ![Alexey\_Wasilyev1](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@Alexey\_Wasilyev1](https://forum.ansible.com/u/Alexey_Wasilyev1)\
**Post date:** [October 22, 2014, 6:13pm UTC](https://forum.ansible.com/t/minimize-ssh-connections-number/16547/6 "2014-10-22T18:13:07Z")

</div>

I know. Just doublecheck it, ansible run ssh with CP option.
