# Output from "fail" too verbose

**URL:** <https://forum.ansible.com/t/output-from-fail-too-verbose/28413>\
**Category:** Ansible Project\
**Created:** [August 24, 2018, 7:33am UTC](https://forum.ansible.com/t/output-from-fail-too-verbose/28413 "2018-08-24T07:33:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uwe\_Sauter](https://avatars.discourse-cdn.com/v4/letter/u/41988e/32.png) [@Uwe\_Sauter](https://forum.ansible.com/u/Uwe_Sauter)\
**Post date:** [August 24, 2018, 7:33am UTC](https://forum.ansible.com/t/output-from-fail-too-verbose/28413/1 "2018-08-24T07:33:32Z")

</div>

Hi all,

I have a list of files where I need to check existence and fail if one doesn't exist.

I'd expect the fail module to \*just\* output the defined message when the condition is true  
but instead the complete item is printed.

Is there a way to make the output less verbose (but keep msg)?

Thanks,

&nbsp;&nbsp;Uwe

#### playbook ####

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 24, 2018, 8:17am UTC](https://forum.ansible.com/t/output-from-fail-too-verbose/28413/2 "2018-08-24T08:17:25Z")

</div>

> I have a list of files where I need to check existence and fail if one  
> doesn't exist.
> 
> I'd expect the fail module to \*just\* output the defined message when  
> the condition is true  
> but instead the complete item is printed.

That's because of the with\_items loop and not fail module.

> Is there a way to make the output less verbose (but keep msg)?

You could write you own callback plugin, then you can get any format you want, or drop loop and do it with Jinja template instead.

> ---  
> - hosts: localhost  
> &nbsp;&nbsp;connection: local  
> &nbsp;&nbsp;gather\_facts: false  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;files:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- /tmp/test1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- /tmp/test2
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- stat:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: '{{ item }}'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: '{{ files }}'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: r
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- fail:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: '{{ item["invocation"]["module\_args"]["path"] }} not found'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: not item.stat.exists  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: ' {{ r.results }}'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop\_control:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: '{{ item["invocation"]["module\_args"]["path"] }}'

Try this

&nbsp;&nbsp;&nbsp;- fail:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: Files not found {{ ', '.join(r.results | rejectattr('stat.exists') | map(attribute='item') | list) }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: r.results | rejectattr('stat.exists') | map(attribute='item') | list | length \> 0

---

<div class="post-metadata">

**Author:** ![Uwe\_Sauter](https://avatars.discourse-cdn.com/v4/letter/u/41988e/32.png) [@Uwe\_Sauter](https://forum.ansible.com/u/Uwe_Sauter)\
**Post date:** [August 24, 2018, 10:42am UTC](https://forum.ansible.com/t/output-from-fail-too-verbose/28413/3 "2018-08-24T10:42:20Z")

</div>

Thanks, that worked. Though it feels unusual and a little like cheating Ansible.

Regards,

&nbsp;&nbsp;Uwe
