# Find module questions

**URL:** <https://forum.ansible.com/t/find-module-questions/23466>\
**Category:** Ansible Project\
**Created:** [January 16, 2017, 4:15pm UTC](https://forum.ansible.com/t/find-module-questions/23466 "2017-01-16T16:15:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reji](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@Reji](https://forum.ansible.com/u/Reji)\
**Post date:** [January 16, 2017, 4:15pm UTC](https://forum.ansible.com/t/find-module-questions/23466/1 "2017-01-16T16:15:34Z")

</div>

I am using Ansible 2.2 and I am running into issues when using the “find” module. My intention is to check for a pattern in a remote host file. Please note the code:

- name: Checking if string exists  
find:  
paths: ‘/home/rnair/test.txt’  
contains: “dev1d111”  
register: output  
become: yes  
become\_user: root

- debug:  
var: output

**OUTPUT:**

ok: [[xxxx.xxx.com](http://xxxx.xxx.com)] =\> {“changed”: false, “examined”: 0, “files”: , “matched”: 0, “msg”: “/home/rnair/test.txt was skipped as it does not seem to be a valid directory or it cannot be accessed\n”}

TASK [par : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[xxxx.xxx.com](http://xxxx.xxx.com)] =\> {  
“output”: {  
“changed”: false,  
“examined”: 0,  
“files”: ,  
“matched”: 0,  
“msg”: “/home/rnair/test.txt was skipped as it does not seem to be a valid directory or it cannot be accessed\n”  
}  
}

Any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 16, 2017, 5:10pm UTC](https://forum.ansible.com/t/find-module-questions/23466/2 "2017-01-16T17:10:13Z")

</div>

paths is for directories to search, not the exact file name. Try this:

- find:  
paths: ‘/home/rnair’  
pattern: ‘test.txt’  
contains: ‘dev1d111’

---

<div class="post-metadata">

**Author:** ![Reji](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@Reji](https://forum.ansible.com/u/Reji)\
**Post date:** [January 17, 2017, 3:27pm UTC](https://forum.ansible.com/t/find-module-questions/23466/3 "2017-01-17T15:27:40Z")

</div>

Brian,

Thanks for your help. Your suggestion worked. However, I am having trouble with the pattern in my contain. My file content is

jdbc:oracle:thin:@dev1d111.xxxxxxx.com:1521/AAAA.xxxxxx.com

I have tried various combinations for my contain parameter and I still cannot get a matched file. Please note my definition:

- name: Checking if database URL needs to be changed  
find:  
paths: ‘/home/rnair’  
pattern: ‘test.txt’  
contains: “_dev1d111_”  
use\_regex: true  
register: result  
become: yes  
become\_user: root

- debug:  
var: result

**OUTPUT**

TASK [par : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[xxxxx.xx.com](http://xxxxx.xx.com)] =\> {  
“result”: {  
“changed”: false,  
“examined”: 10,  
“files”: ,  
“matched”: 0,  
“msg”: “”  
}  
}

Any idea what is missing?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 17, 2017, 7:31pm UTC](https://forum.ansible.com/t/find-module-questions/23466/4 "2017-01-17T19:31:46Z")

</div>

it needs to be a valid regular expression, which your example is not. Try this contains: “._dev1d111._”

---

<div class="post-metadata">

**Author:** ![Reji](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@Reji](https://forum.ansible.com/u/Reji)\
**Post date:** [January 18, 2017, 12:14pm UTC](https://forum.ansible.com/t/find-module-questions/23466/5 "2017-01-18T12:14:38Z")

</div>

Brian,

Thanks for your help. It works. Much appreciated.

---

<div class="post-metadata">

**Author:** ![Bhargava\_Sagar\_C](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Bhargava\_Sagar\_C](https://forum.ansible.com/u/Bhargava_Sagar_C)\
**Post date:** [September 13, 2017, 5:21pm UTC](https://forum.ansible.com/t/find-module-questions/23466/6 "2017-09-13T17:21:41Z")

</div>

Hi,

How can i provide multiple regex patterns in contains attribute and patterns attribute.  
Also how can i pass multiple directories to paths.

Appreciate any help.

---

<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:** [September 14, 2017, 7:15pm UTC](https://forum.ansible.com/t/find-module-questions/23466/7 "2017-09-14T19:15:11Z")

</div>

Use a loop?

...  
&nbsp;&nbsp;&nbsp;&nbsp;contains: "{{item}}"  
...

with\_items:  
&nbsp;&nbsp;&nbsp;- pattern1  
&nbsp;&nbsp;&nbsp;- patten2  
...
