Recursive copy without copying top dir?

14 views
Skip to first unread message

ZillaYT

unread,
Feb 27, 2018, 12:30:09 PM2/27/18
to Ansible Project
Ansible v2.4.0.0

I want to copy the contents of a local directory to my target host, but the recursive option copies the directory itself. That is

- name: Copy local files target
   copy
:
     src
: /tmp/local_dir
     dest
: /some_path/remote_dir
     recurse
: yes

/tmp/local_dir has
- dir1/some_dirs_and_files
- dir2/some_dirs_and_files


The result has this on the target host

/some_path/remote_dir/local_dir/dir1
/some_path/remote_dir/local_dir/dir2

...but I want this
/some_path/remote_dir/dir1
/some_path/remote_dir/dir2

Is this achievable?

Kai Stian Olstad

unread,
Feb 27, 2018, 12:36:49 PM2/27/18
to ansible...@googlegroups.com
The docs have the answer

"src: - If path is a directory, it is copied recursively. In this case, if path ends with "/", only inside contents of that directory are copied to destination. Otherwise, if it does not end with "/", the directory itself with all contents is copied."


--
Kai Stian Olstad

ZillaYT

unread,
Feb 27, 2018, 12:40:23 PM2/27/18
to Ansible Project
Thank you. Sad thing is I've done this before and (now) remember reading that part of the docs.
Reply all
Reply to author
Forward
0 new messages