1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Handle top-level vars for include tasks to match v1 syntax

The "streamlined" syntax will be deprecated at some point in the future.

Fixes #11882
This commit is contained in:
James Cammarata 2015-08-06 17:19:16 -04:00
parent 7062cb3bb7
commit 5eb092b331
2 changed files with 26 additions and 1 deletions

View file

@ -65,6 +65,13 @@ class Base:
# and initialize the base attributes # and initialize the base attributes
self._initialize_base_attributes() self._initialize_base_attributes()
try:
from __main__ import display
self._display = display
except ImportError:
from ansible.utils.display import Display
self._display = Display()
# The following three functions are used to programatically define data # The following three functions are used to programatically define data
# descriptors (aka properties) for the Attributes of all of the playbook # descriptors (aka properties) for the Attributes of all of the playbook
# objects (tasks, blocks, plays, etc). # objects (tasks, blocks, plays, etc).

View file

@ -162,6 +162,16 @@ class Task(Base, Conditional, Taggable, Become):
new_ds['args'] = args new_ds['args'] = args
new_ds['delegate_to'] = delegate_to new_ds['delegate_to'] = delegate_to
# we handle any 'vars' specified in the ds here, as we may
# be adding things to them below (special handling for includes).
# When that deprecated feature is removed, this can be too.
if 'vars' in ds:
if not isinstance(ds['vars'], dict):
raise AnsibleError("vars specified on a task must be a dictionary (got a %s)" % type(ds['vars']), obj=new_ds)
new_ds['vars'] = ds.pop('vars')
else:
new_ds['vars'] = dict()
for (k,v) in ds.iteritems(): for (k,v) in ds.iteritems():
if k in ('action', 'local_action', 'args', 'delegate_to') or k == action or k == 'shell': if k in ('action', 'local_action', 'args', 'delegate_to') or k == action or k == 'shell':
# we don't want to re-assign these values, which were # we don't want to re-assign these values, which were
@ -169,6 +179,14 @@ class Task(Base, Conditional, Taggable, Become):
continue continue
elif k.replace("with_", "") in lookup_loader: elif k.replace("with_", "") in lookup_loader:
self._preprocess_loop(ds, new_ds, k, v) self._preprocess_loop(ds, new_ds, k, v)
else:
# pre-2.0 syntax allowed variables for include statements at the
# top level of the task, so we move those into the 'vars' dictionary
# here, and show a deprecation message as we will remove this at
# some point in the future.
if action == 'include' and k not in self._get_base_attributes():
self._display.deprecated("Specifying include variables at the top-level of the task is deprecated. Please see:\nhttp://docs.ansible.com/ansible/playbooks_roles.html#task-include-files-and-encouraging-reuse\n\nfor currently supported syntax regarding included files and variables")
new_ds['vars'][k] = v
else: else:
new_ds[k] = v new_ds[k] = v