<p>Remove <em>use_regex: yes</em>. Quoting from the <a href="https://docs.ansible.com/ansible/latest/modules/find_module.html" rel="nofollow noreferrer">doc</a></p>

<blockquote>
  <p>If false the patterns are file globs (shell) if true they are python regexes.</p>
</blockquote>

<p>If you want to use Python regex then the pattern would be probably something like this</p>

<pre><code>patterns: '[j]{2}.[j]{2}'
</code></pre>

<p>You probably want to append to file <strong>>></strong></p>

<pre><code>echo {{ item.path }} &gt;&gt; /tmp/results.txt
</code></pre>

CC BY-SA 4.0
2018-09-27T07:21:56.887Z
2018-09-27T07:42:11.813Z
2018-09-27T07:42:11.813Z
Vladimir Botka
<p>My playbook does not create a /tmp/results.txt file, but I expect it to do so with the content of the results of the <code>find</code> module.</p>

<p>Here is my playbook:</p>

<pre><code>- name: Do stuff
  become: yes
  hosts: fun
  tasks:
  - name: Delete directory
    find:
      paths: /home/jdoe/subdir
      patterns: "jj*jj"
      use_regex: yes
    register: find_results
  - shell: "echo {{ item.path }} &gt; /tmp/results.txt"
    with_items: "{{ find_results.files }}"
</code></pre>

<p>A managed node with the "fun" label has this subdirectory:
/home/jdoe/subdir/jj3jj/</p>

<p>What is wrong with my playbook?</p>

<ansible>
How do I get the find module to work in Ansible?
Ranjit
# How do I get the find module to work in Ansible?

(Asked by: username_0 on 2018-09-27)

My playbook does not create a /tmp/results.txt file, but I expect it to do so with the content of the results of the find module.
Here is my playbook:
- name: Do stuff
  become: yes
  hosts: fun
  tasks:
  - name: Delete directory
    find:
      paths: /home/jdoe/subdir
      patterns: "jj*jj"
      use_regex: yes
    register: find_results
  - shell: "echo {{ item.path }} > /tmp/results.txt"
    with_items: "{{ find_results.files }}"

A managed node with the "fun" label has this subdirectory:
/home/jdoe/subdir/jj3jj/
What is wrong with my playbook?

**Tags:** ansible


---

## 1 answers

### Answer by username_1 on 2018-09-27. Score: 1

Remove use_regex: yes. Quoting from the doc

If false the patterns are file globs (shell) if true they are python regexes.

If you want to use Python regex then the pattern would be probably something like this
patterns: '[j]{2}.[j]{2}'

You probably want to append to file >>
echo {{ item.path }} >> /tmp/results.txt


---

