diff options
author | James Cammarata <jimi@sngx.net> | 2015-11-09 16:28:05 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2015-11-09 16:28:54 -0500 |
commit | ccbcfcddfccf5a75e0c39c508160385d97d1477d (patch) | |
tree | a2810886ad26bb49cb015296d03248239d186b9d | |
parent | 37ae2435878b7dd76b812328878be620a93a30c9 (diff) | |
download | ansible-ccbcfcddfccf5a75e0c39c508160385d97d1477d.tar.gz |
Move where we add environment and make it conditional on not existing
Also displays a warning now, because users should not be using that variable
name as it causes a collision with the internal variable of the same name.
-rw-r--r-- | lib/ansible/vars/__init__.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index 402a975fc0..a6f7b3c099 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -46,6 +46,13 @@ from ansible.utils.vars import combine_vars from ansible.vars.hostvars import HostVars from ansible.vars.unsafe_proxy import wrap_var +try: + from __main__ import display + display = display +except ImportError: + from ansible.utils.display import Display + display = Display() + VARIABLE_CACHE = dict() HOSTVARS_CACHE = dict() @@ -320,6 +327,13 @@ class VariableManager: all_vars = combine_vars(all_vars, self._extra_vars) all_vars = combine_vars(all_vars, magic_variables) + # special case for the 'environment' magic variable, as someone + # may have set it as a variable and we don't want to stomp on it + if task and 'environment' not in all_vars: + all_vars['environment'] = task.environment + else: + display.warning("The variable 'environment' appears to be used already, which is also used internally for environment variables set on the task/block/play. You should use a different variable name to avoid conflicts with this internal variable") + # if we have a task and we're delegating to another host, figure out the # variables for that host now so we don't have to rely on hostvars later if task and task.delegate_to is not None and include_delegate_to: @@ -366,7 +380,6 @@ class VariableManager: variables['role_names'] = [r._role_name for r in play.roles] if task: - variables['environment'] = task.environment if task._role: variables['role_path'] = task._role._role_path |