title: Ansible script to copy file from multiple servers
body: <p>Just wanted to understand what method you could have used to copy a directory from 5-10 remote hosts to a destination say a jump server?</p>
  
  <p>One that I have been working on is:</p>
  
  <pre><code>---
  
   - hosts: all
     gather_facts: true
  
     vars:
       src_path: "/source_path/"
       dest_path: "/destination_path/{{ inventory_hostname }}/"
  
     tasks:
      - name: Copy a location from REMOTE server to the LOCAL jump box
        tags: sync-pull
        synchronize:
          # The synchronize module forces–delay-updates to avoid leaving a destination in a broken in-between state if the underlying rsync process encounters an error.
          src: "{{ src_path }}"
          dest: "{{ dest_path }}"
          mode: pull       # In pull mode the remote host in context is the source.
          delete: yes      # Delete files in dest that don't exist (after transfer, not before) in the src path. This option requires recursive=yes.
          recursive: yes
          compress: yes    # Default yes.  Compress file data during the transfer
          times: yes       # Preserve modification times
          rsync_timeout: 15 # Specify a --timeout for the rsync command in seconds.
          rsync_opts:
           - "--exclude=.git"
           - "--exclude=*.log"
           - "--exclude=*.log.gz"
  </code></pre>
  
  <p>There are number of things still trying to figure out.  Some of them are :</p>
  
  <p>1) how to ensure path is selected based on the host.. i.e. Host1 has 3 source_path.  I am not sure how this will be done!</p>
  
  <p>2) If source_path don't have required permission, then script is failing with error:</p>
  
  <p>send_files failed to open \"source_path/iamlog.log\": Permission denied (13)\
  Unable to figure out what can be done here!</p>