title: How to copy files between two nodes using ansible
body: <p>I need to copy file form machine A to machine B whereas my control machine from where i run all my ansible tasks is machine C(local machine)</p>
  
  <p>I have tried the following:</p>
  
  <p><strong>Use scp command in shell module of ansible</strong></p>
  
  <pre><code>hosts: machine2
  user: user2
  tasks:
    - name: Copy file from machine1 to machine2 
      shell: scp user1@machine1:/path-of-file/file1 /home/user2/file1
  </code></pre>
  
  <p>This approach just goes on and on never ends.</p>
  
  <p><strong>use fetch &amp; copy modules</strong></p>
  
  <pre><code>hosts: machine1
  user: user1
  tasks:
    - name: copy file from machine1 to local
      fetch: src=/path-of-file/file1 dest=/path-of-file/file1
  
  hosts: machine2
  user: user2
  tasks:
    - name: copy file from local to machine2
      copy: src=/path-of-file/file1 dest=/path-of-file/file1
  </code></pre>
  
  <p>This approach throws me an error as follows:</p>
  
  <pre><code>error while accessing the file /Users/&lt;myusername&gt;/.ansible/cp/ansible-ssh-machine2-22-&lt;myusername&gt;, error was: [Errno 102] Operation not supported on socket: u'/Users/&lt;myusername&gt;/.ansible/cp/ansible-ssh-machine2-22-&lt;myusername&gt;'
  </code></pre>
  
  <p>Any suggestions would be helpful.</p>