# \[WARNING\]: It is unneccessary to use '{{' in loops, leave variables in loop expressions bare.

**URL:** <https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691>\
**Category:** Ansible Project\
**Created:** [October 16, 2013, 10:19am UTC](https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691 "2013-10-16T10:19:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jurgen\_Haas2](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@Jurgen\_Haas2](https://forum.ansible.com/u/Jurgen_Haas2)\
**Post date:** [October 16, 2013, 10:19am UTC](https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691/1 "2013-10-16T10:19:53Z")

</div>

I’m getting the above warning from the title of this issue and I do understand the meaning, I just have no idea on how to find the loops where by syntax is not correct. Could the warning be extended to provide a filename and line number to display where the error occures?

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [October 16, 2013, 10:27am UTC](https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691/2 "2013-10-16T10:27:31Z")

</div>

​how about running this from your ansible directory:

grep with\_.\*{{ -r​

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 16, 2013, 12:50pm UTC](https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691/3 "2013-10-16T12:50:28Z")

</div>

The meaning of this is that if you have:

with\_items: “{{ foo.bar.baz }}”

You can and should just write:

with\_items: foo.bar.baz

---

<div class="post-metadata">

**Author:** ![Jurgen\_Haas2](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@Jurgen\_Haas2](https://forum.ansible.com/u/Jurgen_Haas2)\
**Post date:** [October 16, 2013, 2:32pm UTC](https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691/4 "2013-10-16T14:32:31Z")

</div>

Sure thing, but I’m stuck because I have many instances with multiline stuff, e.g.

with\_nested:

- [‘a’, ‘b’, ‘c’]
- {{ variable }}

And then a reg-ex is pretty difficult - at least to my knowledge.

---

<div class="post-metadata">

**Author:** ![Jurgen\_Haas2](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@Jurgen\_Haas2](https://forum.ansible.com/u/Jurgen_Haas2)\
**Post date:** [October 16, 2013, 2:33pm UTC](https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691/5 "2013-10-16T14:33:09Z")

</div>

That’s what I thought. But still I’d like to get some hints on where in all the files this has been found by the parser. Isn’t that possible?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 16, 2013, 7:51pm UTC](https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691/6 "2013-10-16T19:51:22Z")

</div>

Not right now.

---

<div class="post-metadata">

**Author:** ![kahlil.hodgson](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@kahlil.hodgson](https://forum.ansible.com/u/kahlil.hodgson)\
**Post date:** [October 16, 2013, 9:59pm UTC](https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691/7 "2013-10-16T21:59:37Z")

</div>

If

grep -E ‘with\_\w+:\s+"?{{’ -r .

and  
grep -E “with\_\w+:\s+'?{{” -r .

do not indicate the problem, then you can rule out a couple of cases.

Next try:

grep -E ‘-\s+"?{{’ -r .

and

grep -E “-\s+'?{{” -r .

That should cover the rest of the possibilities that come to mind.

(Note: I’m using multiple passes to cover off possibilities involving quotes to avoid a more complex regular expression that might not be correct).

Hope this helps.

Kal

---

<div class="post-metadata">

**Author:** ![Jurgen\_Haas2](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@Jurgen\_Haas2](https://forum.ansible.com/u/Jurgen_Haas2)\
**Post date:** [October 17, 2013, 11:52am UTC](https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691/8 "2013-10-17T11:52:35Z")

</div>

Thanks Kal, the only item found is this:

- name: “MySQL | Set the root password for all other domains”  
mysql\_user: user=“root” password=“{{ mysql\_root\_password }}” host=“{{ item }}”  
with\_items:
- “127.0.0.1”
- “::1”
- “{{ inventory\_hostname }}”  
notify: “MySQL | Restart MySQL”

Does that mean that the third item in with\_items should be changed into

- inventory\_hostname

then?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 17, 2013, 1:02pm UTC](https://forum.ansible.com/t/warning-it-is-unneccessary-to-use-in-loops-leave-variables-in-loop-expressions-bare/13691/9 "2013-10-17T13:02:12Z")

</div>

no, it does not, as this is a value in a list, as opposed to the name of the list.
