title: How can I make ansible reuse SSH sessions instead of creating a new one for each task?
body: <p>My corporate firewall policy allows only 20 connections per minute 60 seconds between the same source and destinations.</p>
  <p>Owing to this the ansible play hangs after a while.</p>
  <p>I would like multiple tasks to use the same ssh session rather than creating new sessions. For this purpose i set the below <code>pipelining = True</code> in the local folder <code>ansible.cfg</code> as well as in the command line.</p>
  <pre><code>cat /opt/automation/startservices/ansible.cfg
  
  [defaults]
  host_key_checking = False
  gathering = smart
  [ssh_connection]
  ssh_args = -o ControlMaster=auto -o ControlPersist=600s
  control_path = %(directory)s/%%h-%%r
  pipelining = True
  
  ANSIBLE_SSH_PIPELINING=0 ansible-playbook -i /opt/automation/startservices/finalallmw.hosts /opt/automation/startservices/va_action.yml -e '{ dest_host: myremotehost7 }' -e dest_user=oracle
  </code></pre>
  <p>The playbook is too big to be shared here but it is this task which loops and this is where it hangs due to more than 20 ssh connections in 60 seconds.</p>
  <pre class="lang-yaml prettyprint-override"><code> - name: Copying from &quot;{{ inventory_hostname }}&quot; to this ansible server.
     synchronize:
       src: &quot;{{ item.path }}&quot;
       dest: &quot;{{ playbook_dir }}/homedirbackup/{{ inventory_hostname }}/{{ dtime }}/&quot;
       mode: pull
       copy_links: yes
     with_items:
       - &quot;{{ to_copy.files }}&quot;
  </code></pre>
  <p>With the pipelining settings set, my play still hangs after 20 connections.</p>
  <p>Below are the playbook settings:</p>
  <pre class="lang-yaml prettyprint-override"><code>   hosts: &quot;{{ groups['dest_nodes'] | default(groups['all']) }}&quot;
     user: &quot;{{ USER | default(dest_user) }}&quot;
     any_errors_fatal: True
     gather_facts: false
     tags: always
  
     vars:
       ansible_host_key_checking: false
       ansible_ssh_extra_args: -o StrictHostKeyChecking=no  -o ConnectionAttempts=5
  </code></pre>
  <p>Post suggestions this far on this thread the issue persists. Below is my local directory ansible.cfg</p>
  <pre><code>$ cat /opt/automation/startservices/ansible.cfg
  # config file for ansible -- http://ansible.com/
  # ==============================================
  
  # nearly all parameters can be overridden in ansible-playbook
  # or with command line flags. ansible will read ANSIBLE_CONFIG,
  # ansible.cfg in the current working directory, .ansible.cfg in
  # the home directory or /etc/ansible/ansible.cfg, whichever it
  # finds first
  
  [defaults]
  host_key_checking = False
  roles_path = roles/
  gathering = smart
  [ssh_connection]
  pipelining = True
  ssh_args = -o ControlMaster=auto -o ControlPersist=1200s  -o ControlPath=~/.ansible/cp/%r@%h:%p
  
  [persistent_connection]
  control_path_dir = ~/.ansible/cp
  $
  </code></pre>
  <p>Can you please suggest any solution to the issue on the ansible side where all tasks use the same ssh session and is pipelining not working here?</p>