# How to copy directory from remote machine to ansible machine

**URL:** <https://forum.ansible.com/t/how-to-copy-directory-from-remote-machine-to-ansible-machine/30048>\
**Category:** Ansible Project\
**Created:** [April 3, 2019, 11:08am UTC](https://forum.ansible.com/t/how-to-copy-directory-from-remote-machine-to-ansible-machine/30048 "2019-04-03T11:08:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amit\_ahuja](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@amit\_ahuja](https://forum.ansible.com/u/amit_ahuja)\
**Post date:** [April 3, 2019, 11:08am UTC](https://forum.ansible.com/t/how-to-copy-directory-from-remote-machine-to-ansible-machine/30048/1 "2019-04-03T11:08:14Z")

</div>

Hi,

i want to know if there is any way to copy complete directory from remote machine to local ansible machine . i tried to used fetch method but it is copying files with complete path which i dont want . pls help .

thanks  
Amit

---

<div class="post-metadata">

**Author:** ![Vinu\_Vajravel](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@Vinu\_Vajravel](https://forum.ansible.com/u/Vinu_Vajravel)\
**Post date:** [April 3, 2019, 11:39am UTC](https://forum.ansible.com/t/how-to-copy-directory-from-remote-machine-to-ansible-machine/30048/2 "2019-04-03T11:39:28Z")

</div>

SCP you tried ?

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [April 3, 2019, 1:45pm UTC](https://forum.ansible.com/t/how-to-copy-directory-from-remote-machine-to-ansible-machine/30048/3 "2019-04-03T13:45:24Z")

</div>

```auto
If you don't want the complete path, you can set "flat: yes" in the fetch task and it will flatten the directory for you.

--Tony

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 3, 2019, 7:46pm UTC](https://forum.ansible.com/t/how-to-copy-directory-from-remote-machine-to-ansible-machine/30048/4 "2019-04-03T19:46:29Z")

</div>

[https://docs.ansible.com/ansible/latest/modules/synchronize\_module.html](https://docs.ansible.com/ansible/latest/modules/synchronize_module.html)  
see 'mode' specifically the 'pull' value
