Question:
I need to find a files in unknown directory place and remove them.
Tried to use “find” module, register its output, and pass it to “file”.
Even if I see path registered, I can not use it later:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
< TASK [print find_result] > ok: [1.2.3.4] => { "find_result": { "changed": false, "examined": 3119, "files": [ { "atime": 1483973253.7295375, ... "mode": "0600", "mtime": 1483973253.7295375, "nlink": 1, "path": "/tmp/delme", |
My playbook is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
- hosts: "{{ target }}" become: no vars: find_what: "delme*" find_where: "/tmp" tasks: - name: finding files find: paths: "{{ find_where }}" patterns: "{{ find_what }}" recurse: "yes" file_type: "file" register: find_result # \/ for debugging - name: print find_result debug: var=find_result - name: remove files file: path= "{{ item.path }}" state=absent with_items: "{{ find_result.files }}" |
Answer:
There’s a syntax flaw in file
task – space after =
.
Try:
1 2 3 4 5 6 |
- name: remove files file: path: "{{ item.path }}" state: absent with_items: "{{ find_result.files }}" |