I have a directory:
/users/rolando/myfile
I want to copy "myfile" to hostname "targetserver" in directory:
/home/rolando/myfile
What is the syntax in the playbook to do this? Examples I found with the copy
command look like it's more about copying a file from a source directory on a remote server to a target directory on the same remote server.
The line in my playbook .yml I tried that failed:
- copy:
src='/users/rolando/myfile'
dest='rolando@targetserver:/home/rolando/myfile'
What am I doing wrong?
Copying Files between Directories on Remote Machine Ansible copy allows you to copy the files from one directory to another on the same remote machine. But this is only for files, not for the directories. You can use the remote_src parameter to let Ansible know your intentions. The below code will copy /tmp/test.
To copy a file from remote to local in ansible we use ansible fetch module. Fetch module is used to fetch the files from remote to local machine. In the following example i will show you how to copy a file from remote to local using ansible fetch module. Note: If you execute above playbook the target.
From copy synopsis:
The
copy
module copies a file on the local box to remote locations.
- hosts: targetserver
tasks:
- copy:
src: /users/rolando/myfile
dest: /users/rolando/myfile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With