Can somebody go into details about the difference between these two?
Is there really a difference between them?
Can somebody go into details about the difference between these two?
Is there really a difference between them?
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.
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"???
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"
with_lines: echo -e a\nb\nc
yields three tasks, a, b, and c. Whereas
- action: debug msg="$item"
with_pipe:
- echo a
- echo b
- echo c
will do the same, but the items here can include newlines.
Daniel
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)
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.
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.