If you need to copy files between two (2) nodes, using Ansible, then you can do the following:

This solution uses the synchronize module, specifically using the delegate_to:source-server keywords. I needed this when migrating data between servers during a platform upgrade — the files had to go directly from server A to server B without passing through the Ansible control node.

The synchronize module wraps rsync under the hood, so rsync needs to be installed on both nodes. Make sure SSH key-based auth is set up between the two servers, not just from your control machine. If the servers can’t reach each other directly, you’ll need to use fetch and copy modules instead, which routes the files through the control node.

- hosts: serverB
  tasks:    
   - name: Copy Remote-To-Remote (from serverA to serverB)
     synchronize: src=https://andrewodendaal.com/copy/from_serverA dest=/copy/to_serverB
     delegate_to: serverA