ansible find with_items register results

I’m documenting this here for posterity because I’ve been struggling with a solution off & on for months. Of course, the solution was staring me in the face the whole time, but I couldn’t see it.

When using with_items/loop with one task, and then looping over the results in a second task, the syntax is a little bit funky.

- name: get files to remove for uninstall
  find:
    paths: "{{item}}"
    patterns: ".*"
    use_regex: True
    file_type: directory
  register: output
  with_items:
    - "{{paths}}"

- name: debug
  debug:
    var: output

- name: debug loop
  debug:
    var: item.1.path
  with_subelements:
    - "{{output.results}}"
    - files

- name: uninstall app
  file:
    state: absent
    path: "{{item.1.path}}"
  with_subelements:
    - "{{output.results}}"
    - files
  when: output is defined


There are probably multiple ways to do this (feel free to share your own in reply.. there may be a simpler way than my own), but the way I found that works is to use with_subelements on the subsequent tasks.  I hope this helps someone else out there that struggles with this.