Commit 60944b81 by Michael DeHaan

Provide warning about "with_items: '{{ loop }}'" being redundant only when {{…

Provide warning about "with_items: '{{ loop }}'" being redundant only when {{ starts the expression value.  Fixes #4582.
parent 2bd8cb57
...@@ -82,7 +82,7 @@ class Task(object): ...@@ -82,7 +82,7 @@ class Task(object):
# code to allow "with_glob" and to reference a lookup plugin named glob # code to allow "with_glob" and to reference a lookup plugin named glob
elif x.startswith("with_"): 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.") utils.warning("It is unneccessary to use '{{' in loops, leave variables in loop expressions bare.")
plugin_name = x.replace("with_","") plugin_name = x.replace("with_","")
...@@ -94,7 +94,7 @@ class Task(object): ...@@ -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)) 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']: 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.") utils.warning("It is unneccessary to use '{{' in conditionals, leave variables in loop expressions bare.")
ds[x] = "jinja2_compare %s" % (ds[x]) ds[x] = "jinja2_compare %s" % (ds[x])
elif x.startswith("when_"): elif x.startswith("when_"):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment