run long shell command on remote servers using ansible

Well I can't tell what your problem is exactly, but the error indicates that you have a syntax error in your command. Which is almost certainly related to something being escaped or not translated properly as it is executed.

A couple things I have to suggest. First use the yaml syntax to include a block of text which includes line endings.

- name: Run Script
  shell: |
    machines=(machineA machineB machineC)
    for machine in $(shuf -e ${machines[@]}); do
        ssh -o StrictHostKeyChecking=no david@$machine 'ls -1 /process/snap/{{ folder }}/*' |
        parallel -j{{ threads }} 'scp -o StrictHostKeyChecking=no david@${machine}:{} /data/files/'
      [ $? -eq 0 ] && break
    done

I think, that your fragment may have some bashisms. You may need to specify that your script be executed via bash instead of /bin/sh.

- name: Run command that requires bash
  shell: echo 'not a very good example.
  args:
    executable: /bin/bash

You might also want to add a set -x as the first line of your fragment. The more verbose output from the shell should help you see what exactly the error is.

Of course I would also suggest you try to use Ansible modules to do this instead. I suspect maybe the synchronize module combined with the async features.