I need to copy a file between two remote nodes:
- node A is a managed node where the file exists
- node B is a managed node where the file should be copied
Please note that my control node, from where I run all my Ansible tasks, is none of the above mentioned nodes.
I have tried the following:
Use scp
command in shell module of Ansible
- hosts: machine2
user: user2
tasks:
- name: Copy file from machine1 to machine2
shell: scp user1@machine1:/path-of-file/file1 /home/user2/file1
This approach just goes on and on never ends.
Use the fetch
and copy
modules
- 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
This approach throws me an error as follows:
error while accessing the file /Users//.ansible/cp/ansible-ssh-machine2-22-, error was: [Errno 102] Operation not supported on socket: u'/Users//.ansible/cp/ansible-ssh-machine2-22-'
How can I achieve this?