Custom item output

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] => (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,

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

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.

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.

Maybe just a changeable logging level will do?

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

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…

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?

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

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

Any comments on my suggestion ?

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.

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

-jlk

(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?

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 ?

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.

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.

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.