From 09994c18f31cbcb0e9358f6dbf8bbb936f33e5a0 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 9 Nov 2015 21:04:24 -0500 Subject: [PATCH] Correct logic around determining environment variable existence Fixes #13105 --- lib/ansible/vars/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index a6f7b3c099..20cb58adeb 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -329,10 +329,11 @@ class VariableManager: # 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 task: + if '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