Skip to content

Instantly share code, notes, and snippets.

@cat-bro
Created July 27, 2023 02:17
Show Gist options
  • Save cat-bro/37760ccbdb27f137239d8dfba51275e1 to your computer and use it in GitHub Desktop.
Save cat-bro/37760ccbdb27f137239d8dfba51275e1 to your computer and use it in GitHub Desktop.
ansible: iterate over a list of directories
- name: Get a list of directories within a directory
find:
paths:
- "{{ parent_dir_name }}"
file_type: directory
depth: 1
register: list_of_dirs
- name: Iterate over list of dirs
debug:
msg:
"Found directory {{ item }} in {{ parent_dir_name }}"
with_items: "{{ list_of_dirs.files | map(attribute='path') | map('basename') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment