Provide warning about "with_items: '{{ loop }}'" being redundant only when {{ starts the expression value. Fixes #4582.

This commit is contained in:
Michael DeHaan 2013-10-19 14:24:12 -04:00
parent 2bd8cb5790
commit 60944b81f0

View file

@ -82,7 +82,7 @@ class Task(object):
# code to allow "with_glob" and to reference a lookup plugin named glob
elif x.startswith("with_"):
if isinstance(ds[x], basestring) and '{{' in ds[x]:
if isinstance(ds[x], basestring) and ds[x].lstrip().startswith("{{"):
utils.warning("It is unneccessary to use '{{' in loops, leave variables in loop expressions bare.")
plugin_name = x.replace("with_","")
@ -94,7 +94,7 @@ class Task(object):
raise errors.AnsibleError("cannot find lookup plugin named %s for usage in with_%s" % (plugin_name, plugin_name))
elif x in [ 'changed_when', 'failed_when', 'when']:
if isinstance(ds[x], basestring) and '{{' in ds[x]:
if isinstance(ds[x], basestring) and ds[x].lstrip().startswith("{{"):
utils.warning("It is unneccessary to use '{{' in conditionals, leave variables in loop expressions bare.")
ds[x] = "jinja2_compare %s" % (ds[x])
elif x.startswith("when_"):