diff --git a/lib/ansible/runner/action_plugins/template.py b/lib/ansible/runner/action_plugins/template.py index ba7cad985cf..80a7c4e7824 100644 --- a/lib/ansible/runner/action_plugins/template.py +++ b/lib/ansible/runner/action_plugins/template.py @@ -56,17 +56,17 @@ class ActionModule(object): if 'first_available_file' in inject: found = False for fn in self.runner.module_vars.get('first_available_file'): - fn = utils.template(self.runner.basedir, fn, inject) - fn = utils.path_dwim(self.runner.basedir, fn) - if os.path.exists(fn): - source = fn + fnt = utils.template(self.runner.basedir, fn, inject) + fnd = utils.path_dwim(self.runner.basedir, fnt) + if os.path.exists(fnd): + source = fnt found = True break if not found: result = dict(failed=True, msg="could not find src in first_available_file list") return ReturnData(conn=conn, comm_ok=False, result=result) - - source = utils.template(self.runner.basedir, source, inject) + else: + source = utils.template(self.runner.basedir, source, inject) # template the source data locally & transfer try: diff --git a/test/TestPlayBook.py b/test/TestPlayBook.py index dd4eb6ab40f..9dec825b5c4 100644 --- a/test/TestPlayBook.py +++ b/test/TestPlayBook.py @@ -130,7 +130,7 @@ class TestPlaybook(unittest.TestCase): return result def test_one(self): - pb = os.path.join(self.test_dir, 'playbook1.yml') + pb = 'test/playbook1.yml' actual = self._run(pb) # if different, this will output to screen diff --git a/test/playbook1.yml b/test/playbook1.yml index ddad2bc5424..bbadc7ec0f9 100644 --- a/test/playbook1.yml +++ b/test/playbook1.yml @@ -41,7 +41,10 @@ # not be triggered twice because it's already triggered - 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: - on change 1 - on change 2