# How to copy directory recursively using pattern to remote machine?

**URL:** <https://forum.ansible.com/t/how-to-copy-directory-recursively-using-pattern-to-remote-machine/33062>\
**Category:** Ansible Project\
**Created:** [June 1, 2020, 11:49am UTC](https://forum.ansible.com/t/how-to-copy-directory-recursively-using-pattern-to-remote-machine/33062 "2020-06-01T11:49:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankit2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Ankit2](https://forum.ansible.com/u/Ankit2)\
**Post date:** [June 1, 2020, 11:49am UTC](https://forum.ansible.com/t/how-to-copy-directory-recursively-using-pattern-to-remote-machine/33062/1 "2020-06-01T11:49:09Z")

</div>

Hello All,

I have got the following playbooks where i am trying to copy directories and all its contents recursively which is present in project repo. For identifying the correct directory, i am using a variable which holds the pattern value. For some reason, the task is skipped and the full verbose too doesn’t give me enough information about where it is failing. Can someone please suggest.

`

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [June 1, 2020, 12:00pm UTC](https://forum.ansible.com/t/how-to-copy-directory-recursively-using-pattern-to-remote-machine/33062/2 "2020-06-01T12:00:20Z")

</div>

> Hello All,
> 
> I have got the following playbooks where i am trying to copy directories and all its contents recursively which is  
> present in project repo. For identifying the correct directory, i am using a variable which holds the pattern value. For  
> some reason, the task is skipped and the full verbose too doesn't give me enough information about where it is failing.  
> Can someone please suggest.
> 
> \>  
> ---  
> -hosts:all  
> gather\_facts:no  
> become:yes  
> vars:  
> appid:'1554'  
> tasks:  
> -name:Copyeach file over that matches the given pattern  
> copy:  
> src:"{{ item }}"  
> dest:"/tmp"  
> with\_fileglob:  
> -/home/DS/ram/playbooks/app\_dir\_{{appid }}\*

I think you need to wrap the argument into double\_quotes like that:

with\_fileglob:  
&nbsp;&nbsp;- "/home/DS/ram/playbooks/app\_dir\_{{appid }}\*"

Otherwise it wouldn't interpolate the appid variable.

Regards  
&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Ankit2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Ankit2](https://forum.ansible.com/u/Ankit2)\
**Post date:** [June 1, 2020, 12:48pm UTC](https://forum.ansible.com/t/how-to-copy-directory-recursively-using-pattern-to-remote-machine/33062/3 "2020-06-01T12:48:49Z")

</div>

Hi Stefan,

Thanks for your comment, i am getting the same issue even after putting that in double quotes.

---

<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:** [June 1, 2020, 3:38pm UTC](https://forum.ansible.com/t/how-to-copy-directory-recursively-using-pattern-to-remote-machine/33062/4 "2020-06-01T15:38:58Z")

</div>

you are not passing a 'glob' to fileglob, in any case the problem is  
that it is returning an empty list, examine it in a debug statement  
until you get the output you expect.
