Merge pull request #1541 from dhozac/fix-first_available_file

Fix first_available_file and add test-case
This commit is contained in:
Michael DeHaan 2012-11-06 12:45:11 -08:00
commit 1b8d912d2a
3 changed files with 11 additions and 8 deletions

View file

@ -56,17 +56,17 @@ class ActionModule(object):
if 'first_available_file' in inject: if 'first_available_file' in inject:
found = False found = False
for fn in self.runner.module_vars.get('first_available_file'): for fn in self.runner.module_vars.get('first_available_file'):
fn = utils.template(self.runner.basedir, fn, inject) fnt = utils.template(self.runner.basedir, fn, inject)
fn = utils.path_dwim(self.runner.basedir, fn) fnd = utils.path_dwim(self.runner.basedir, fnt)
if os.path.exists(fn): if os.path.exists(fnd):
source = fn source = fnt
found = True found = True
break break
if not found: if not found:
result = dict(failed=True, msg="could not find src in first_available_file list") result = dict(failed=True, msg="could not find src in first_available_file list")
return ReturnData(conn=conn, comm_ok=False, result=result) return ReturnData(conn=conn, comm_ok=False, result=result)
else:
source = utils.template(self.runner.basedir, source, inject) source = utils.template(self.runner.basedir, source, inject)
# template the source data locally & transfer # template the source data locally & transfer
try: try:

View file

@ -130,7 +130,7 @@ class TestPlaybook(unittest.TestCase):
return result return result
def test_one(self): def test_one(self):
pb = os.path.join(self.test_dir, 'playbook1.yml') pb = 'test/playbook1.yml'
actual = self._run(pb) actual = self._run(pb)
# if different, this will output to screen # if different, this will output to screen

View file

@ -41,7 +41,10 @@
# not be triggered twice because it's already triggered # not be triggered twice because it's already triggered
- name: test template - name: test template
action: template src=sample.j2 dest=/tmp/ansible_test_data_template.out action: template src=$item dest=/tmp/ansible_test_data_template.out
first_available_file:
- nonexistantfile
- sample.j2
notify: notify:
- on change 1 - on change 1
- on change 2 - on change 2