This seems simple enough but I can't find the ansible/jinja way to do it nor the correct keywords to find some pointers.
There's a list of file names (firstlist) (read from a file if it makes anything easier).
There's a second list (secondlist) with partial filenames to filter the first one. This second list can have elements that don't match.
/tmp/filelist.txt contents:
A-ok.txt
B-ok.txt
C-ok.txt
Tasks extract:
- name: Read filelist
command: cat /tmp/filelist.txt
register: filelist_results
- name: "[FACT] filelist"
set_fact:
firstlist: "{{ filelist_results.stdout_lines }}"
secondlist: ['A', 'C', 'D']
- name: "print it"
ansible.builtin.debug:
msg: "{{ item }}"
loop: "{{ firstlist }}" # <--- need to filter here?
Would result in looping just:
A-ok.txt
C-ok.txt
If secondlist contained the full filename, adding:
when: item in secondlist
would be enough.
It seems select() is half the answer but I can't find the correct test to match the partial filename from the second list