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
  - name: Delete directory
      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?

1 Answer 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.