title: Ansible ssh fails with error: Data could not be sent to remote host
body: <p>I have an ansible playbook that executes a shell script on remote host "10.8.8.88" as many times as the number files provided as parameter</p>
  
  <pre><code>ansible-playbook test.yml -e files="file1,file2,file3,file4"
  </code></pre>
  
  <p>playbook looks like below:</p>
  
  <pre><code>- name: Call ssh
    shell: ~./execute.sh {{ item }}
    with_items: {{ files.split(',') }}
  </code></pre>
  
  <p>This works fine for fewer files say 10 to 15 files. But I happen to have 145 files in the argument. </p>
  
  <p>This is when the execution broke and play failed mid-way with below error message:</p>
  
  <pre><code>TASK [shell] *******************************************************************
   [WARNING]: conditional statements should not include jinja2 templating
  delimiters such as {{ }} or {% %}. Found: entrycurrdb.stdout.find("{{ BASEPATH
  }}/{{ vars[(item | splitext)[1].split('.')[1]] }}/{{ item | basename }}") == -1
  and actualfile.stat.exists == True
   [WARNING]: sftp transfer mechanism failed on [10.8.8.88]. Use ANSIBLE_DEBUG=1
  to see detailed information
   [WARNING]: scp transfer mechanism failed on [10.8.8.88]. Use ANSIBLE_DEBUG=1
  to see detailed information
  fatal: [10.8.8.88]: UNREACHABLE! =&gt; {"changed": false, "msg": "Data could not be sent to remote host \"10.8.8.88\". Make sure this host can be reached over ssh: ", "unreachable": true}
  
  NO MORE HOSTS LEFT *************************************************************
  
  PLAY RECAP *********************************************************************
  10.8.8.88                 : ok=941  changed=220  unreachable=1    failed=0    skipped=145  rescued=0    ignored=0   
  localhost                  : ok=7    changed=3    unreachable=0    failed=0    skipped=3    rescued=0    ignored=0   
  
  Build step 'Execute shell' marked build as failure
  Finished: FAILURE
  </code></pre>
  
  <p>I have the latest Ansible and the "pipeline" and "ssh" settings in ansible.cfg are as defaults. </p>
  
  <p>I have the following questions.</p>
  
  <ol>
  <li><p>How can I resolve the above issue? </p></li>
  <li><p>I guess this could be due to a network issue. Is it possible to run infinite ssh ping to the remote server for testing purposes to see if the ansible command-line breaks? It will help me prove my case.  A sample command that keeps pinging the remote using ssh is what I'm looking for.</p></li>
  <li><p>It is possible to force ansible to retry ssh connection a few times in case of such failures so that it may connect in during retries. If so, I would appreciate where and how that can be set in ansible-playbook code as vars variable and not in ansible.cfg file? 
  <a href="https://docs.ansible.com/ansible/2.4/intro_configuration.html#retries" rel="nofollow noreferrer">https://docs.ansible.com/ansible/2.4/intro_configuration.html#retries</a></p></li>
  </ol>
  
  <p>Something similar to:</p>
  
  <pre><code>   vars:
      ansible_ssh_private_key_file: "{{ key1 }}"
  </code></pre>
  
  <p>Many Thanks !! </p>