Commit 72fd9718 by Seth Vidal

fall through file source list: first_available_file support

add first_available_file look up to _execute_template and _execute_copy
to runner.

add this data to playbook handler so it can be included into module_vars
parent 40f54698
...@@ -390,8 +390,10 @@ class PlayBook(object): ...@@ -390,8 +390,10 @@ class PlayBook(object):
module_args = tokens[1] module_args = tokens[1]
# include task specific vars # include task specific vars
module_vars = task.get('vars') module_vars = task.get('vars', {})
if 'first_available_file' in task:
module_vars['first_available_file'] = task.get('first_available_file')
# tasks can be direct (run on all nodes matching # tasks can be direct (run on all nodes matching
# the pattern) or conditional, where they ran # the pattern) or conditional, where they ran
# as the result of a change handler on a subset # as the result of a change handler on a subset
......
...@@ -390,6 +390,20 @@ class Runner(object): ...@@ -390,6 +390,20 @@ class Runner(object):
# apply templating to source argument # apply templating to source argument
inject = self.setup_cache.get(conn.host,{}) inject = self.setup_cache.get(conn.host,{})
# if we have first_available_file in our vars
# look up the files and use the first one we find as src
if 'first_available_file' in self.module_vars:
found = False
for fn in self.module_vars.get('first_available_file'):
fn = utils.template(fn, inject, self.setup_cache)
if os.path.exists(fn):
source = fn
found = True
break
if not found:
return (host, True, dict(failed=True, msg="could not find src"), '')
source = utils.template(source, inject, self.setup_cache) source = utils.template(source, inject, self.setup_cache)
# transfer the file to a remote tmp location # transfer the file to a remote tmp location
...@@ -480,6 +494,20 @@ class Runner(object): ...@@ -480,6 +494,20 @@ class Runner(object):
# apply templating to source argument so vars can be used in the path # apply templating to source argument so vars can be used in the path
inject = self.setup_cache.get(conn.host,{}) inject = self.setup_cache.get(conn.host,{})
# if we have first_available_file in our vars
# look up the files and use the first one we find as src
if 'first_available_file' in self.module_vars:
found = False
for fn in self.module_vars.get('first_available_file'):
fn = utils.template(fn, inject, self.setup_cache)
if os.path.exists(fn):
source = fn
found = True
break
if not found:
return (host, True, dict(failed=True, msg="could not find src"), '')
source = utils.template(source, inject, self.setup_cache) source = utils.template(source, inject, self.setup_cache)
(host, ok, data, err) = (None, None, None, None) (host, ok, data, err) = (None, None, None, None)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment