# ansible 2.5 with\_items -\> loop conversion

**URL:** <https://forum.ansible.com/t/ansible-2-5-with-items-loop-conversion/31035>\
**Category:** Ansible Project\
**Created:** [August 13, 2019, 8:28pm UTC](https://forum.ansible.com/t/ansible-2-5-with-items-loop-conversion/31035 "2019-08-13T20:28:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [August 13, 2019, 8:28pm UTC](https://forum.ansible.com/t/ansible-2-5-with-items-loop-conversion/31035/1 "2019-08-13T20:28:54Z")

</div>

So I’ve been looking at the porting guide for 2.5 (i’m going from 2.4 to 2.7).

I have this task that outputs a list of version numbers as strings and registers the output. I then loop through the registered variable using with\_items. I’ve been looking at converting this to loop. I realize that with\_items isn’t deprecated (yet), but i’m just trying to be proactive.

I’m running into issues with how loop iterates over register.stdout\_lines var vs with\_items.

In addition, I noticed that if i register lines that start with numbers, instead of words, the result of with\_items is different, throwing variable is not defined errors.  
Here’s a simplified version of what i’m doing with two different sets of variables to illustrate the differences.  
[https://pastebin.com/ai1Bu9G0](https://pastebin.com/ai1Bu9G0)

So my questions are:

- How do I convert with\_items to loop when used in conjunction with a registered var register.stdout\_lines?
- And as a secondary question, why does with\_items treat numbers vs characters differently?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [August 13, 2019, 8:33pm UTC](https://forum.ansible.com/t/ansible-2-5-with-items-loop-conversion/31035/2 "2019-08-13T20:33:13Z")

</div>

When you switch from this syntax using with\_items:

with\_items:

- “{{ numberedvars.stdout\_lines }}”

Your loop should not look the same, instead it should be:

loop: “{{ numberedvars.stdout\_lines }}”

with\_items does something called flattening, which will take a nested list of lists, and flatten it. loop does not do flattening, and by using the `-` on a new line, indicates that you are creating a list element in YAML.

I cannot necessarily answer your numbers vs characters question, without more context.

---

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [August 14, 2019, 1:09pm UTC](https://forum.ansible.com/t/ansible-2-5-with-items-loop-conversion/31035/3 "2019-08-14T13:09:10Z")

</div>

Thanks Matt! That was indeed the issue!

The other question isn’t important, so don’t waste time on it unless you’re just curious. But if you look at the output between the two variable examples, numberedvars vs wordvars towards the bottom, they are different in what it outputs (one gives “proper” output while the other gives VARIABLE IS NOT DEFINED).

Again, not super important, as i’m not trying to solve that issue, just something I noticed.
