Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy file from localhost to remote host in Ansible playbook?

Tags:

ansible

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?

like image 242
Rolando Avatar asked Jun 16 '17 18:06

Rolando


People also ask

How do I copy files from one directory to another in Ansible?

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.

How copy file from remote server to local machine in Ansible?

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.


1 Answers

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
like image 119
Konstantin Suvorov Avatar answered Oct 04 '22 20:10

Konstantin Suvorov