How can I have a nested loop with a fileglob pattern?
The trick is to transform the fileglob return value into a list via the split
function, so you can iterate over the values:
- name: copy authorized keys
authorized_key:
user: "{{ item.0.username }}"
key: "{{ lookup('file', item.1) }}"
with_nested:
- "{{ users }}"
- "{{ lookup('fileglob', 'public_keys/*').split(',') }}"
Note that using bare variables, without {{
and }}
, for with_items
was deprecated in Ansible v2.