From f044fc344ba05ba45059d6fa0eb5e958bce2ca3b Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sat, 6 Apr 2013 18:32:36 -0400 Subject: [PATCH] When using roles, or other includes, the path to DWIM inside is the path of the task include file. --- examples/playbooks/roles/foo/handlers/main.yml | 4 ++++ lib/ansible/playbook/play.py | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/playbooks/roles/foo/handlers/main.yml b/examples/playbooks/roles/foo/handlers/main.yml index d41caad6f9..e8a60de47d 100644 --- a/examples/playbooks/roles/foo/handlers/main.yml +++ b/examples/playbooks/roles/foo/handlers/main.yml @@ -3,4 +3,8 @@ - name: blippy shell: echo notifier called, and the value of x is '{{ x }}' +# within a role, it's possible to include other task files as well. By default, we +# can reference files in the same directory without doing anything special: + +- include: other.yml diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 74ef90e2e4..567158633a 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -223,9 +223,13 @@ class Play(object): for t in tokens[1:]: (k,v) = t.split("=", 1) mv[k] = utils.template(self.basedir, v, mv) - include_file = utils.template(self.basedir, tokens[0], mv) - data = utils.parse_yaml_from_file(utils.path_dwim(self.basedir, include_file)) - results += self._load_tasks(data, mv, included_additional_conditions, original_file=include_file) + dirname = self.basedir + if original_file: + dirname = os.path.dirname(original_file) + include_file = utils.template(dirname, tokens[0], mv) + include_filename = utils.path_dwim(dirname, include_file) + data = utils.parse_yaml_from_file(include_filename) + results += self._load_tasks(data, mv, included_additional_conditions, original_file=include_filename) elif type(x) == dict: results.append(Task(self,x,module_vars=task_vars, additional_conditions=additional_conditions)) else: