with_first_found using a fileglob?

261 views
Skip to first unread message

Gonzalo Servat

unread,
Dec 4, 2013, 11:32:29 PM12/4/13
to ansible-project
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

Gonzalo Servat

unread,
Dec 8, 2013, 3:35:32 PM12/8/13
to ansible-project
Any suggestions?

Michael DeHaan

unread,
Dec 9, 2013, 9:12:06 AM12/9/13
to ansible...@googlegroups.com
Two options.

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








Any suggestions?
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Brian Coca

unread,
Dec 9, 2013, 10:28:01 AM12/9/13
to ansible...@googlegroups.com
with_pipe: find <paths> -name 'glob'|head -n 1

Gonzalo Servat

unread,
Dec 9, 2013, 3:07:24 PM12/9/13
to ansible-project
Thanks Michael/Brian. Didn't know about with_pipe... will give that a try or I will look at modifying with_first_found.

- GS


On Tue, Dec 10, 2013 at 2:28 AM, Brian Coca <bria...@gmail.com> wrote:
with_pipe: find <paths> -name 'glob'|head -n 1

--
Reply all
Reply to author
Forward
0 new messages