with_first_found using a fileglob?

Hi All,

I’d like to search a bunch of paths for the first “glob” match. For example:

  • debug: msg=“{{ item }}”

with_first_found:

  • files: “httpd-*.rpm”

paths:

  • RPMs/{{ ansible_distribution_version }}

  • RPMs/{{ ansible_distribution_version }}.{{ ansible_distribution_release }}

I understand that the fileglob may match multiple files (by nature) but, in my case, I will only have one file that matches the pattern ‘httpd-*.rpm’ and if I have multiple, I want to pick the first of the match in the ordered list of paths.

Essentially what I’m trying to achieve is uploading a distribution specific version of a file and the filename has a version number that changes over time, and I don’t want to store it in a variable.

Any ideas?

GS

Any suggestions?

Two options.

You can use with_fileglob which will search one fileglob or you could enhance “with_first_found” to understand fileglobs.

with_pipe: find -name ‘glob’|head -n 1

Thanks Michael/Brian. Didn’t know about with_pipe… will give that a try or I will look at modifying with_first_found.

  • GS