From 4714cbeec8043df968b182c799610a1775f36341 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Fri, 14 Aug 2015 00:33:36 -0400 Subject: [PATCH] Override post validation of environment to allow bare variables Also prints a deprecated warning if a bare variable is detected, so that we can remove this in a future version. Fixes #11912 --- lib/ansible/playbook/task.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 788c70b568..f0023fecf4 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -19,11 +19,13 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +from six import string_types + from ansible.errors import AnsibleError from ansible.parsing.mod_args import ModuleArgsParser from ansible.parsing.splitter import parse_kv -from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping +from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping, AnsibleUnicode from ansible.plugins import module_loader, lookup_loader @@ -211,6 +213,17 @@ class Task(Base, Conditional, Taggable, Become): ''' return value + def _post_validate_environment(self, attr, value, templar): + ''' + Override post validation of vars on the play, as we don't want to + template these too early. + ''' + for env_item in value: + if isinstance(env_item, (string_types, AnsibleUnicode)) and env_item in templar._available_variables.keys(): + self._display.deprecated("Using bare variables for environment is deprecated. Update your playbooks so that the environment value uses the full variable syntax ('{{foo}}')") + break + return templar.template(value, convert_bare=True) + def get_vars(self): all_vars = dict() if self._block: