diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index ce0aee735d..62af94dd74 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -65,6 +65,13 @@ class Base: # and initialize the 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 # descriptors (aka properties) for the Attributes of all of the playbook # objects (tasks, blocks, plays, etc). diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 68a399027a..5ae056f604 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -162,6 +162,16 @@ class Task(Base, Conditional, Taggable, Become): new_ds['args'] = args 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(): 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 @@ -170,7 +180,15 @@ class Task(Base, Conditional, Taggable, Become): elif k.replace("with_", "") in lookup_loader: self._preprocess_loop(ds, new_ds, k, v) else: - new_ds[k] = v + # 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: + new_ds[k] = v return super(Task, self).preprocess_data(new_ds)