mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
4d352e69fc
commit
091a90ee8b
1 changed files with 9 additions and 2 deletions
|
@ -391,6 +391,7 @@ class Play(object):
|
||||||
tokens = shlex.split(str(x['include']))
|
tokens = shlex.split(str(x['include']))
|
||||||
items = ['']
|
items = ['']
|
||||||
included_additional_conditions = list(additional_conditions)
|
included_additional_conditions = list(additional_conditions)
|
||||||
|
include_vars = {}
|
||||||
for k in x:
|
for k in x:
|
||||||
if k.startswith("with_"):
|
if k.startswith("with_"):
|
||||||
plugin_name = k[5:]
|
plugin_name = k[5:]
|
||||||
|
@ -403,13 +404,19 @@ class Play(object):
|
||||||
elif k == 'when':
|
elif k == 'when':
|
||||||
included_additional_conditions.insert(0, utils.compile_when_to_only_if("jinja2_compare %s" % x[k]))
|
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"):
|
elif k in ("include", "vars", "default_vars", "only_if", "sudo", "sudo_user"):
|
||||||
pass
|
continue
|
||||||
else:
|
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', {}))
|
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:
|
if 'vars' in x:
|
||||||
task_vars = utils.combine_vars(task_vars, x['vars'])
|
task_vars = utils.combine_vars(task_vars, x['vars'])
|
||||||
|
|
||||||
if 'only_if' in x:
|
if 'only_if' in x:
|
||||||
included_additional_conditions.append(x['only_if'])
|
included_additional_conditions.append(x['only_if'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue