From 091a90ee8bdc50e7f6d033d1157a3055c8f8fb61 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 16 Sep 2013 16:12:36 -0500 Subject: [PATCH] Allow includes to follow the standard format Previously, includes had to receive variables via a special 'vars' field. With this patch, the include syntax becomes a more natural datastructure without special fields and is more akin to the way role includes/dependencies work. Tested with the following playbook: --- - hosts: localhost connection: local tasks: - { include: inc1.yml, a: 1 } - include: inc2.yml b: 2 - include: inc3.yml with_items: - x - y - z Fixes #3481 --- lib/ansible/playbook/play.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 1c833a4de4..919cb5ed8f 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -391,6 +391,7 @@ class Play(object): tokens = shlex.split(str(x['include'])) items = [''] included_additional_conditions = list(additional_conditions) + include_vars = {} for k in x: if k.startswith("with_"): plugin_name = k[5:] @@ -403,13 +404,19 @@ class Play(object): elif k == 'when': included_additional_conditions.insert(0, utils.compile_when_to_only_if("jinja2_compare %s" % x[k])) elif k in ("include", "vars", "default_vars", "only_if", "sudo", "sudo_user"): - pass + continue else: - raise errors.AnsibleError("parse error: task includes cannot be used with other directives: %s" % k) + include_vars[k] = x[k] default_vars = utils.combine_vars(self.default_vars, x.get('default_vars', {})) + + # append the vars defined with the include (from above) + # as well as the old-style 'vars' element. The old-style + # vars are given higher precedence here (just in case) + task_vars = utils.combine_vars(task_vars, include_vars) if 'vars' in x: task_vars = utils.combine_vars(task_vars, x['vars']) + if 'only_if' in x: included_additional_conditions.append(x['only_if'])