# How do i optimize performance of Ansible playbook with regards to ssh connections

**URL:** <https://forum.ansible.com/t/how-do-i-optimize-performance-of-ansible-playbook-with-regards-to-ssh-connections/33952>\
**Category:** Ansible Project\
**Created:** [October 2, 2020, 1:24pm UTC](https://forum.ansible.com/t/how-do-i-optimize-performance-of-ansible-playbook-with-regards-to-ssh-connections/33952 "2020-10-02T13:24:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Easy\_King](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@Easy\_King](https://forum.ansible.com/u/Easy_King)\
**Post date:** [October 2, 2020, 1:24pm UTC](https://forum.ansible.com/t/how-do-i-optimize-performance-of-ansible-playbook-with-regards-to-ssh-connections/33952/1 "2020-10-02T13:24:25Z")

</div>

I have the below playbook test1.yml that gets istat data for 26 subfolders under this directory /var/myfile/pdf.

tasks:

- name: List directoriesraw: "ls -d “/var/myfile/pdf/\*/”  
register: subdir

- name: List pid files  
raw: “istat {{ item }}”  
with\_items: “{{ subdir.stdout\_lines }}”

I run the playbook and it takes 29 seconds to complete

time ANSIBLE\_SSH\_PIPELINING=True ansible-playbook -i=10.9.9.12, -f 30 test1.yml -vvv

After the playbook completes below is the time taken details output:

Output:

real 0m29.144s user 0m6.206s sys 0m5.618s

I now put the same code with istat task in include\_tasks` file like below.

Playbook test2.yml

tasks:

- name: List directories  
raw: "ls -d “/var/myfile/pdf/\*/”  
register: subdir

- name: List pid files  
include\_tasks: “innertest.yml”  
with\_items: “{{ subdir.stdout\_lines }}”

cat innertest.yml

- raw: “istat {{ item }}” time ANSIBLE\_SSH\_PIPELINING=True ansible-playbook -i=10.9.9.12, -f 30 test2.yml -vvv

Output:

real 0m59.044s user 0m18.203s sys 0m10.118s

As you can see the time with the same amount of task has more than doubled due to include\_tasks

In the debug, I also see there are 26 ssh connections triggered for the 26 sub-directories with\_items for the same target host 10.9.9.12

I’m not sure of how this works internally but it would have been nice to have a single ssh connection for istat for 26 sub-directories on the same host for performance reasons.

Is there a way to increase the performance for include\_tasks and bringing down the number of ssh connections to the same host ?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [October 3, 2020, 6:57pm UTC](https://forum.ansible.com/t/how-do-i-optimize-performance-of-ansible-playbook-with-regards-to-ssh-connections/33952/2 "2020-10-03T18:57:37Z")

</div>

> I have the below playbook test1.yml that gets istat data for 26 subfolders under this directory /var/myfile/pdf.
> 
> tasks:
> 
> - name: List directories  
> raw: "ls -d "/var/myfile/pdf/\*/"  
> register: subdir
> 
> - name: List pid files  
> raw: "istat {{ item }}"  
> with\_items: "{{ subdir.stdout\_lines }}"

What kind of server / device is that? I would rather use "find" module instead of "raw".  
What does istat actually?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
