# Recursive copy without copying top dir?

**URL:** <https://forum.ansible.com/t/recursive-copy-without-copying-top-dir/26861>\
**Category:** Ansible Project\
**Created:** [February 27, 2018, 5:30pm UTC](https://forum.ansible.com/t/recursive-copy-without-copying-top-dir/26861 "2018-02-27T17:30:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [February 27, 2018, 5:30pm UTC](https://forum.ansible.com/t/recursive-copy-without-copying-top-dir/26861/1 "2018-02-27T17:30:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 27, 2018, 5:36pm UTC](https://forum.ansible.com/t/recursive-copy-without-copying-top-dir/26861/2 "2018-02-27T17:36:18Z")

</div>

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."

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [February 27, 2018, 5:40pm UTC](https://forum.ansible.com/t/recursive-copy-without-copying-top-dir/26861/3 "2018-02-27T17:40:22Z")

</div>

Thank you. Sad thing is I’ve done this before and (now) remember reading that part of the docs.
