# with\_lines vs with\_pipe

**URL:** <https://forum.ansible.com/t/with-lines-vs-with-pipe/12284>\
**Category:** Ansible Project\
**Created:** [February 2, 2013, 6:14pm UTC](https://forum.ansible.com/t/with-lines-vs-with-pipe/12284 "2013-02-02T18:14:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [February 2, 2013, 6:14pm UTC](https://forum.ansible.com/t/with-lines-vs-with-pipe/12284/1 "2013-02-02T18:14:41Z")

</div>

Can somebody go into details about the difference between these two?

Is there really a difference between them?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 2, 2013, 6:21pm UTC](https://forum.ansible.com/t/with-lines-vs-with-pipe/12284/2 "2013-02-02T18:21:25Z")

</div>

Sure.

with\_lines runs against a text file and gives you each line in the text file

with\_pipe runs against a shell command, and gives you the lines in the  
shell command

given "with\_fileglob" or "with\_lines" is what you want MOST of the  
time, with\_pipe is going to be used a bit less.

Also in many cases, if you are reading something that is a list of  
packages to install (for example), usage of vars\_files to assign a  
list and using "with\_items" is also probably more appropriate.

It is, however, useful for walking through lists produced by things  
that are not already in YAML.

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [February 2, 2013, 6:29pm UTC](https://forum.ansible.com/t/with-lines-vs-with-pipe/12284/3 "2013-02-02T18:29:38Z")

</div>

If with\_lines runs against a file, why can't we just give it a list of files, and have to use the syntax "\*cat\* /path/to/filename"???

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [February 2, 2013, 6:36pm UTC](https://forum.ansible.com/t/with-lines-vs-with-pipe/12284/4 "2013-02-02T18:36:37Z")

</div>

Yves Dorfsman wrote:

> Can somebody go into details about the difference between these two?
> 
> Is there really a difference between them?

Yes. with\_lines creates a list of each line in the output. with\_pipe is  
primarily meant to be used as $PIPE(...), but can also be used to use the  
full contents of several commands. So,

- action: debug msg="$item"  
&nbsp;&nbsp;with\_lines: echo -e a\nb\nc

yields three tasks, a, b, and c. Whereas

- action: debug msg="$item"  
&nbsp;&nbsp;with\_pipe:  
&nbsp;&nbsp;- echo a  
&nbsp;&nbsp;- echo b  
&nbsp;&nbsp;- echo c

will do the same, but the items here can include newlines.

Daniel

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 2, 2013, 6:40pm UTC](https://forum.ansible.com/t/with-lines-vs-with-pipe/12284/5 "2013-02-02T18:40:26Z")

</div>

Sorry, with\_lines also operates against a pipe. It should have really  
really been called "with\_lines\_in\_pipe" but that's set now.

(If you want lines in a file, vars\_files is almost always a better fit anyway)

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [February 2, 2013, 6:51pm UTC](https://forum.ansible.com/t/with-lines-vs-with-pipe/12284/6 "2013-02-02T18:51:55Z")

</div>

> Sorry, with\_lines also operates against a pipe. It should have really  
> really been called "with\_lines\_in\_pipe" but that's set now.

Yes.

> (If you want lines in a file, vars\_files is almost always a better fit anyway)

With the exception that, it is my understanding that, vars\_file expects a yaml file instead of a simple list of lines.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 2, 2013, 7:09pm UTC](https://forum.ansible.com/t/with-lines-vs-with-pipe/12284/7 "2013-02-02T19:09:07Z")

</div>

> > 
> 
> With the exception that, it is my understanding that, vars\_file expects a  
> yaml file instead of a simple list of lines.

This is true, though this also allows it to operate on structured data.

So you could have a list of hashes, for instance, and be able to get  
at things like:

${item.subkey}

The 'cat' approach works when you don't want that.
