# Custom item output

**URL:** <https://forum.ansible.com/t/custom-item-output/14554>\
**Category:** Ansible Project\
**Created:** [February 12, 2014, 6:55pm UTC](https://forum.ansible.com/t/custom-item-output/14554 "2014-02-12T18:55:46Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rumen\_Telbizov](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Rumen\_Telbizov](https://forum.ansible.com/u/Rumen_Telbizov)\
**Post date:** [February 12, 2014, 6:55pm UTC](https://forum.ansible.com/t/custom-item-output/14554/1 "2014-02-12T18:55:46Z")

</div>

Hello ansible list,

Here’s a quick question that I was trying to find an answer for. Maybe I am missing the obvious but I can’t find a way to control the output of the “item” variable during a loop (with\_items) while the playbook is running.

Example:

changed: [[s1.server.com](http://s1.server.com)] =\> ( **item=/path/to/something** )

This shows what the current item of the current loop iteration looks like. It might be a very large json object and could clobber the output screen with unnecessary information. I would like to be able to control exactly what is been output. Is it possible to do this?

Thank you in advance,

---

<div class="post-metadata">

**Author:** ![adam2](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@adam2](https://forum.ansible.com/u/adam2)\
**Post date:** [February 12, 2014, 7:27pm UTC](https://forum.ansible.com/t/custom-item-output/14554/2 "2014-02-12T19:27:29Z")

</div>

I find this annoying too. +1 on my vote.

---

<div class="post-metadata">

**Author:** ![Rumen\_Telbizov](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Rumen\_Telbizov](https://forum.ansible.com/u/Rumen_Telbizov)\
**Post date:** [February 13, 2014, 5:38pm UTC](https://forum.ansible.com/t/custom-item-output/14554/3 "2014-02-13T17:38:43Z")

</div>

It seems like there isn’t a way to customize the output of an item (or otherwise any task).

Would anybody else be interested in having this feature? I could file a request/ticket with a suggestion.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 13, 2014, 5:41pm UTC](https://forum.ansible.com/t/custom-item-output/14554/4 "2014-02-13T17:41:09Z")

</div>

So let’s not file a request, because the first thing I will ask is to have a discussion here. Let’s talk about what you want to do and if we can come to something.

---

<div class="post-metadata">

**Author:** ![Nick\_Maslov](https://avatars.discourse-cdn.com/v4/letter/n/7ab992/32.png) [@Nick\_Maslov](https://forum.ansible.com/u/Nick_Maslov)\
**Post date:** [February 13, 2014, 5:48pm UTC](https://forum.ansible.com/t/custom-item-output/14554/5 "2014-02-13T17:48:13Z")

</div>

Maybe just a changeable logging level will do?

Sometimes I just want to see exit code from operation, rather than a full blown trace.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 13, 2014, 6:00pm UTC](https://forum.ansible.com/t/custom-item-output/14554/6 "2014-02-13T18:00:34Z")

</div>

I’m more curious how it would work when the item is useful and neccessary in some cases and not others.

It does not feel like a global setting and it also should not be _nothing_ in the task output, or should it?

Also, trying to avoid an additional task keyword…

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 13, 2014, 6:01pm UTC](https://forum.ansible.com/t/custom-item-output/14554/7 "2014-02-13T18:01:16Z")

</div>

Also this wasn’t posted about exit codes (shown only with -v), it was posted about listing the item it was walking over in a loop, right?

---

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [February 13, 2014, 6:07pm UTC](https://forum.ansible.com/t/custom-item-output/14554/8 "2014-02-13T18:07:13Z")

</div>

Maybe there could be an option to simply control the total size of each output line.  
the length-cut is simple to implement and I don’t see how you could smarty extract and show only the important information.  
length=0 (default) means: I want to see everything

---

<div class="post-metadata">

**Author:** ![Rumen\_Telbizov](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Rumen\_Telbizov](https://forum.ansible.com/u/Rumen_Telbizov)\
**Post date:** [February 13, 2014, 6:56pm UTC](https://forum.ansible.com/t/custom-item-output/14554/9 "2014-02-13T18:56:55Z")

</div>

Thanks for starting a discussion.

Here is how I see a feature like this.  
How about if we introduce a new keyword called say "print: " similar to debug but being an auxiliary keyword rather than the main task. So with this you can control some extra output that comes after [changed] [servername] =\> “here’s my custom output”.If this print keyword exists in a task that has a loop then it will basically be printed on every iteration.

Now if you don’t specify print: then ansible keeps doing what it does now - it prints nothing for a regular task and the full “item” content for a task with a loop. In other words the default won’t change the current behavior.  
If we _do_ have the print keyword present though then ansible still prints the [changed] [servername] part but after it, it also adds whatever “print” says - which if in a loop might contain the whole item if the author of the playbook decided to do so or maybe only parts of it: {{item.blah}} is now {{item.changed}} or something ?

My thoughts only though.

Cheers,  
Rumen Telbizov

---

<div class="post-metadata">

**Author:** ![Rumen\_Telbizov](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Rumen\_Telbizov](https://forum.ansible.com/u/Rumen_Telbizov)\
**Post date:** [February 14, 2014, 5:57pm UTC](https://forum.ansible.com/t/custom-item-output/14554/10 "2014-02-14T17:57:08Z")

</div>

Any comments on my suggestion ?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 14, 2014, 6:21pm UTC](https://forum.ansible.com/t/custom-item-output/14554/11 "2014-02-14T18:21:47Z")

</div>

I’m not fond of the size control option as that seems a bit abstract for most people to comprehend (no offense).

I might possibly think of something like “filter\_results” that only saves and shows the hash keys that match the list?

- shell: /bin/true  
filter\_results: [‘rc’, ‘stdout’]

I still feel this is a little confusing, but I like it better than something that is print specific, and may also be usable in other contexts, and would also not require modifying any of the callback code.

---

<div class="post-metadata">

**Author:** ![Jesse\_Keating](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Jesse\_Keating](https://forum.ansible.com/u/Jesse_Keating)\
**Post date:** [February 14, 2014, 6:36pm UTC](https://forum.ansible.com/t/custom-item-output/14554/12 "2014-02-14T18:36:24Z")

</div>

At first glance, the print: thing seems reasonable and not too confusing.

-jlk

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 14, 2014, 6:59pm UTC](https://forum.ansible.com/t/custom-item-output/14554/13 "2014-02-14T18:59:10Z")

</div>

(A) I would think it might mean to print

(B) which might be fine if it ignored -v

(C) in which case I’d expect print: True to maybe print everything, and it also take a list of attributes?

---

<div class="post-metadata">

**Author:** ![Rumen\_Telbizov](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Rumen\_Telbizov](https://forum.ansible.com/u/Rumen_Telbizov)\
**Post date:** [February 14, 2014, 7:54pm UTC](https://forum.ansible.com/t/custom-item-output/14554/14 "2014-02-14T19:54:05Z")

</div>

I think of “print” exactly like “debug” - it accepts a completely arbitrary template as a parameter, with variables and plain text, but instead of being the main target/task like debug it is an auxiliary one and simply complements the main output after status and server. It is a non-mandatory keyword and if omitted we show what we show today.

With regards to the name - feel free to use any other word if more appropriate: “echo” maybe ?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 14, 2014, 7:56pm UTC](https://forum.ansible.com/t/custom-item-output/14554/15 "2014-02-14T19:56:29Z")

</div>

I’m not looking forward to seeing the “print” parameter plumb down into the awareness of all the callbacks to do that.

I think I’d rather see it filter what gets recorded at that point, in which case, it’s really not print, it’s something like “filter\_fields” or “keep\_fields”.

And if provided is your idea that it would always print, or would it use -v? Debug does force -v for that step now.

---

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [February 15, 2014, 9:04pm UTC](https://forum.ansible.com/t/custom-item-output/14554/16 "2014-02-15T21:04:00Z")

</div>

Hello,  
Since my line-cut 80 chars with nice '...' Has not been chosen; I can propose something at the other side of the abstraction gap:

Why not have log-plugins that are given a bit of context and then they decide how to log, what to filter etc.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 15, 2014, 10:15pm UTC](https://forum.ansible.com/t/custom-item-output/14554/17 "2014-02-15T22:15:19Z")

</div>

I really don’t want to introduce another level of plugins at this time.

We already have too many of these and this is a bit of a niche issue/question.
