0

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

ansible-playbook test.yml -e files="file1,file2,file3,file4"

playbook looks like below:

- name: Call ssh
  shell: ~./execute.sh {{ item }}
  with_items: {{ files.split(',') }}

This works fine for fewer files say 10 to 15 files. But I happen to have 145 files in the argument.

This is when the execution broke and play failed mid-way with below error message:

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! => {"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

I have the latest Ansible and the "pipeline" and "ssh" settings in ansible.cfg are as defaults.

I have the following questions.

  1. How can I resolve the above issue?

  2. 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.

  3. 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? https://docs.ansible.com/ansible/2.4/intro_configuration.html#retries

Something similar to:

   vars:
    ansible_ssh_private_key_file: "{{ key1 }}"

Many Thanks !!

Ashar
  • 2,942
  • 10
  • 58
  • 122
  • The task that fails during your run does not correspond to the one your gave as an example. The title (`name`) is not aligned and there is a warning complaining about a malformed `when` clause that does not exist in your example. Are you sure it is the good task ? If not, please provide a correct [MCVE](https://stackoverflow.com/help/minimal-reproducible-example). Did you run ansible with debug enabled (or with -vvv) as advised to see if you had more info ? That might tell you what went wrong at sftp/scp time to upload the module script. – Zeitounator Dec 02 '19 at 16:58
  • The playbook is just a sample and not the exact syntax. I had run with the -vv option but will also try with the -vvv option. Meanwhile, can you answer the 3. third point if you are aware? – Ashar Dec 02 '19 at 17:10
  • "Devil hides in details": Always provide the most possible accurate information when asking for debugging help. Besides `-vvv` you should also enable ansible debugging as advised in the error message to see if you have more info. Regarding your point 3) you can set that in your environment: https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-ssh-retries – Zeitounator Dec 02 '19 at 17:24

0 Answers0