1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

enable use of multiple terms in first_found

This commit is contained in:
trbs 2013-06-19 16:37:29 +02:00
parent fc2d25eb82
commit 87c7fa9138

View file

@ -83,6 +83,23 @@
# - files: foo.${inventory_hostname} # - files: foo.${inventory_hostname}
# skip: true # skip: true
# example a role with default configuration and configuration per host
# you can set multiple terms with their own files and paths to look through.
# consider a role that sets some configuration per host falling back on a default config.
#
#- name: some configuration template
# template: src={{ item }} dest=/etc/file.cfg mode=0444 owner=root group=root
# with_first_found:
# - files:
# - ${inventory_hostname}/etc/file.cfg
# paths:
# - ../../../templates.overwrites
# - ../../../templates
# - files:
# - etc/file.cfg
# paths:
# - templates
# the above will return an empty list if the files cannot be found at all # the above will return an empty list if the files cannot be found at all
# if skip is unspecificed or if it is set to false then it will return a list # if skip is unspecificed or if it is set to false then it will return a list
# error which can be caught bye ignore_errors: true for that action. # error which can be caught bye ignore_errors: true for that action.
@ -101,8 +118,6 @@
# ignore_errors: true # ignore_errors: true
from ansible import utils, errors from ansible import utils, errors
import os import os
@ -123,6 +138,7 @@ class LookupModule(object):
if isinstance(term, dict): if isinstance(term, dict):
anydict = True anydict = True
total_search = []
if anydict: if anydict:
for term in terms: for term in terms:
if isinstance(term, dict): if isinstance(term, dict):
@ -144,9 +160,6 @@ class LookupModule(object):
paths = paths.replace(';', ' ') paths = paths.replace(';', ' ')
pathlist = paths.split(' ') pathlist = paths.split(' ')
total_search = []
if not pathlist: if not pathlist:
total_search = filelist total_search = filelist
else: else:
@ -155,7 +168,7 @@ class LookupModule(object):
f = os.path.join(path, fn) f = os.path.join(path, fn)
total_search.append(f) total_search.append(f)
else: else:
total_search = [term] total_search.append(term)
else: else:
total_search = terms total_search = terms