Search code examples
ansible

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


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?


Solution

  • 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