# how to use regex in copy or other module

**URL:** <https://forum.ansible.com/t/how-to-use-regex-in-copy-or-other-module/22696>\
**Category:** Ansible Project\
**Created:** [October 1, 2016, 3:49am UTC](https://forum.ansible.com/t/how-to-use-regex-in-copy-or-other-module/22696 "2016-10-01T03:49:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user81](https://avatars.discourse-cdn.com/v4/letter/u/ba9def/32.png) [@user81](https://forum.ansible.com/u/user81)\
**Post date:** [October 1, 2016, 3:49am UTC](https://forum.ansible.com/t/how-to-use-regex-in-copy-or-other-module/22696/1 "2016-10-01T03:49:31Z")

</div>

I need to copy files from managed node to control machines.

A machine’s tomcat path : /usr/local/tomcat-aux  
B machine’s tomcat path : /usr/local/tomcat-hk  
actually there is not only these two instance.  
so I’ve tried below methods, but failed.

name: copy file to tomcat path  
copy: src=/deploy/a.conf dest=/usr/local/tomcat\*/

Thanks in advance~

---

<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:** [October 2, 2016, 7:12am UTC](https://forum.ansible.com/t/how-to-use-regex-in-copy-or-other-module/22696/2 "2016-10-02T07:12:15Z")

</div>

copy module doesn't support regexp, only a handful modules do, and if they do it's documented in the individual module documentation.

You example you can written like this:

- name: Find tomcat directories  
&nbsp;&nbsp;&nbsp;find:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paths=/usr/local  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;patterns=tomcat\*  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file\_type=directory  
&nbsp;&nbsp;&nbsp;register: result

- name: copy file to tomcat path  
&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src=/deploy/a.conf  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest={{ item.path }}  
&nbsp;&nbsp;&nbsp;with\_items: result.files

---

<div class="post-metadata">

**Author:** ![user81](https://avatars.discourse-cdn.com/v4/letter/u/ba9def/32.png) [@user81](https://forum.ansible.com/u/user81)\
**Post date:** [October 3, 2016, 3:14am UTC](https://forum.ansible.com/t/how-to-use-regex-in-copy-or-other-module/22696/3 "2016-10-03T03:14:44Z")

</div>

Got it. thank you so much!

在 2016年10月2日星期日 UTC+8下午3:12:51，Kai Stian Olstad写道：
