# with\_items stat too verbose

**URL:** <https://forum.ansible.com/t/with-items-stat-too-verbose/29546>\
**Category:** Ansible Project\
**Created:** [January 28, 2019, 3:54pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546 "2019-01-28T15:54:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjwagner.dba](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rjwagner.dba](https://forum.ansible.com/u/rjwagner.dba)\
**Post date:** [January 28, 2019, 3:54pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/1 "2019-01-28T15:54:39Z")

</div>

Hey all-

I’m using stat and with\_items to check proper ownership of various files. Is there any way to reduce the volume of output (i.e., eliminate everything in red, below)?

rowagn@localhost:~/data-platform/oracle/ansible/db12r2$ cat test.yml

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [January 28, 2019, 5:31pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/2 "2019-01-28T17:31:21Z")

</div>

using -v should be enough to show changes but, not the whole output.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [January 28, 2019, 7:11pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/3 "2019-01-28T19:11:39Z")

</div>

Hi,

check out the label directive for loop\_control:  
[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_loops.html#loop-control](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#loop-control)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![rjwagner.dba](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rjwagner.dba](https://forum.ansible.com/u/rjwagner.dba)\
**Post date:** [January 30, 2019, 3:06pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/4 "2019-01-30T15:06:55Z")

</div>

Hey Jonathan - thanks for the suggestion, but -v doesn’t help. If I include no\_log: True, including -v just outputs the same:

TASK [Confirming ownership of filesystems] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> (item=(censored due to no\_log)) =\> {“censored”: “the output has been hidden due to the fact that ‘no\_log: true’ was specified for this result”}  
ok: [localhost] =\> (item=(censored due to no\_log)) =\> {“censored”: “the output has been hidden due to the fact that ‘no\_log: true’ was specified for this result”}

Rob

---

<div class="post-metadata">

**Author:** ![rjwagner.dba](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rjwagner.dba](https://forum.ansible.com/u/rjwagner.dba)\
**Post date:** [January 30, 2019, 3:09pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/5 "2019-01-30T15:09:00Z")

</div>

Hey Felix - can you elaborate? I’m already using:

loop\_control:

label: “{{ item.item }}”

As shown in my post. It doesn’t quench the output of the items. Am I missing something?

Rob

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [January 30, 2019, 8:43pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/6 "2019-01-30T20:43:24Z")

</div>

Hi Rob,

> Hey Felix - can you elaborate? I'm already using:
> 
> loop\_control:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: "{{ item.item }}"
> 
> As shown in my post. It doesn't quench the output of the items. Am  
> I missing something?

sorry, I guess I misunderstood something. The problem is that assert  
always enables verbose output, so you cannot get rid of item  
completely. What you can do is tidy up item so only the important  
things are in there.

You could try something like

&nbsp;&nbsp;loop: |  
&nbsp;&nbsp;&nbsp;&nbsp;{{ filesystems\_stat.results | map(attribute='item')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\> zip(filesystems\_stat.results | map(attribute='stat.pw\_name'))  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\> list }}

Then you should be able to access item.item via item.0 and  
item.stat.pw\_name via item.1, i.e. the rest of the task would be

&nbsp;&nbsp;assert:  
&nbsp;&nbsp;&nbsp;&nbsp;that: item.1 == 'root'  
&nbsp;&nbsp;loop\_control:  
&nbsp;&nbsp;&nbsp;&nbsp;label: "{{ item.0 }}"

(I haven't tested this, so it might contain bugs, but in principle that  
should work. Note that the zip filter is Ansible specific, while the  
map and list filters are generic Jinja2.)

(Also: with\_items does the same as loop if you give it a simple list;  
you should switch to loop in such cases, and stop using with\_items if  
not explicitly needed.)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![rjwagner.dba](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rjwagner.dba](https://forum.ansible.com/u/rjwagner.dba)\
**Post date:** [February 6, 2019, 5:36pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/7 "2019-02-06T17:36:52Z")

</div>

Thanks Felix. That’s a clever idea. I tested it and I get:

ok: [localhost] =\> (item=/dev) =\> {  
“changed”: false,  
“item”: [  
“/dev”,  
“root”  
],  
“msg”: “All assertions passed”  
}  
ok: [localhost] =\> (item=/home) =\> {  
“changed”: false,  
“item”: [  
“/home”,  
“root”  
],  
“msg”: “All assertions passed”  
}

I don’t really understand why it needs to include “item” in the dict (i.e., after =\> ), since it’s already present in the output (i.e., before =\> ), but this is better than the original. Thanks again.

Rob

---

<div class="post-metadata">

**Author:** ![rjwagner.dba](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rjwagner.dba](https://forum.ansible.com/u/rjwagner.dba)\
**Post date:** [February 8, 2019, 9:40pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/8 "2019-02-08T21:40:59Z")

</div>

So I noticed that older versions (2.1.1) of ansible didn’t have this problem, and I noticed that the verbosity of assert is caused by the following line in assert.py:

result[‘\_ansible\_verbose\_always’] = True

If I comment that out, I get the quieter behavior I (and others, based on some reported github issues) am looking for. So can anyone explain the purpose of the above line? Why was it added to assert.py? What is \_ansible\_verbose\_always for? Could I add another parameter to assert.py (maybe quiet) and, if set to True, then do not set result[‘\_ansible\_verbose\_always’] to True? I appreciate I’m getting into the weeds here, but I found it curious that assert got noisy in more recent versions.

Rob

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [February 9, 2019, 3:18pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/9 "2019-02-09T15:18:38Z")

</div>

Hi Rob,

> So I noticed that older versions (2.1.1) of ansible didn't have this  
> problem, and I noticed that the verbosity of assert is caused by the  
> following line in assert.py:
> 
> result['\_ansible\_verbose\_always'] = True
> 
> If I comment that out, I get the quieter behavior I (and others,  
> based on some reported github issues) am looking for. So can anyone

I assume you are talking about this issue:  
[https://github.com/ansible/ansible/issues/27124](https://github.com/ansible/ansible/issues/27124)

> explain the purpose of the above line? What is  
> \_ansible\_verbose\_always for?

That's easy: it makes the module behave as if -v is specified on the  
ansible command line: it always produces verbose output when the assert  
module is used.

> Why was it added to assert.py?

That's a good one. As you probably read in the issue, nobody remembers,  
so it is unlikely someone suddenly can provide an explanation here 🙂

> Could I add another parameter to assert.py (maybe quiet) and, if set  
> to True, then do not set result['\_ansible\_verbose\_always'] to True?

Sure; that's essentially what @bcoca suggested here:  
[https://github.com/ansible/ansible/issues/27124#issuecomment-316855948](https://github.com/ansible/ansible/issues/27124#issuecomment-316855948)

Feel free to create a PR which does that.

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![rjwagner.dba](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rjwagner.dba](https://forum.ansible.com/u/rjwagner.dba)\
**Post date:** [February 11, 2019, 6:59pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/10 "2019-02-11T18:59:51Z")

</div>

Thanks Felix. Working on a PR now.

Rob

---

<div class="post-metadata">

**Author:** ![Thuan1](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@Thuan1](https://forum.ansible.com/u/Thuan1)\
**Post date:** [December 19, 2020, 3:10pm UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/11 "2020-12-19T15:10:18Z")

</div>

Hi,

I have the same issue.  
I tried this method but it didn’t work on Ansible 2.9.16.  
Am I missing something ?

---

<div class="post-metadata">

**Author:** ![Thuan1](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@Thuan1](https://forum.ansible.com/u/Thuan1)\
**Post date:** [December 21, 2020, 2:46am UTC](https://forum.ansible.com/t/with-items-stat-too-verbose/29546/12 "2020-12-21T02:46:01Z")

</div>

I’ve figured it out.

Thanks for the o.p and the contributor solution !
