# sending mail while using assert?

**URL:** <https://forum.ansible.com/t/sending-mail-while-using-assert/31831>\
**Category:** Ansible Project\
**Created:** [December 16, 2019, 9:01pm UTC](https://forum.ansible.com/t/sending-mail-while-using-assert/31831 "2019-12-16T21:01:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![evnflow](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@evnflow](https://forum.ansible.com/u/evnflow)\
**Post date:** [December 16, 2019, 9:01pm UTC](https://forum.ansible.com/t/sending-mail-while-using-assert/31831/1 "2019-12-16T21:01:18Z")

</div>

Is there a way you can send a mail with-in assert when any\_errors\_fatal: true ? I have tried to do it by using set\_fact still, but still not having success in sending the disk limit size via email.

- name: Assert that the disk limit ({{ disk\_limit }}) has not exceeded  
assert:  
that: ( (disk\_usage|float)/mount.size\_total ) \< disk\_limit|float  
msg: “Disk usage {{ disk\_usage\_ratio\_s }} exceeds {{ disk\_limit\_ratio\_s }}”  
any\_errors\_fatal: true

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [December 16, 2019, 9:30pm UTC](https://forum.ansible.com/t/sending-mail-while-using-assert/31831/2 "2019-12-16T21:30:06Z")

</div>

> Is there a way you can send a mail with-in assert when any\_errors\_fatal:  
> true ?
> 
> - name: Assert that the disk limit ({{ disk\_limit }}) has not exceeded  
> &nbsp;&nbsp;assert:  
> &nbsp;&nbsp;&nbsp;&nbsp;that: ( (disk\_usage|float)/mount.size\_total ) \< disk\_limit|float  
> &nbsp;&nbsp;&nbsp;&nbsp;msg: "Disk usage {{ disk\_usage\_ratio\_s }} exceeds {{ disk\_limit\_ratio\_s  
> }}"  
> &nbsp;&nbsp;any\_errors\_fatal: true

FWIW. Conditionally send the email and end the host. For example

&nbsp;&nbsp;- block:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- mail:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;body: |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Disk usage {{ disk\_usage\_ratio\_s }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exceeds {{ disk\_limit\_ratio\_s }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- meta: end\_host  
&nbsp;&nbsp;&nbsp;&nbsp;when: ((disk\_usage|float)/mount.size\_total) \> disk\_limit|float

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![evnflow](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@evnflow](https://forum.ansible.com/u/evnflow)\
**Post date:** [December 18, 2019, 1:18pm UTC](https://forum.ansible.com/t/sending-mail-while-using-assert/31831/3 "2019-12-18T13:18:54Z")

</div>

Thanks that worked! Only issue is now that it is sending an email with the status of all the mounts one at a time. Is there anyway I can limit email to the on mount that actually hits the threshold?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [December 18, 2019, 2:57pm UTC](https://forum.ansible.com/t/sending-mail-while-using-assert/31831/4 "2019-12-18T14:57:11Z")

</div>

"It is sending an email with the status of \*all\* the mounts" ???

Why is that? Have you tested the condition?

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![evnflow](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@evnflow](https://forum.ansible.com/u/evnflow)\
**Post date:** [December 18, 2019, 3:21pm UTC](https://forum.ansible.com/t/sending-mail-while-using-assert/31831/5 "2019-12-18T15:21:37Z")

</div>

> yes… So one mount is at 80 percent threshold. when the playbook runs it sends individual emails for every mount on the server that has not reached the 80 percent… I am trying the proper way to get the output after the assert to send the email with only the mount that is at 80%.

FAILED! =\> {  
“assertion”: “( (disk\_usage|float)/mount.size\_total ) \< disk\_limit|float”,  
“changed”: false,  
“evaluated\_to”: false,  
“msg”: “Disk usage 80.0% exceeds 80.0%”

---

<div class="post-metadata">

**Author:** ![evnflow](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@evnflow](https://forum.ansible.com/u/evnflow)\
**Post date:** [December 18, 2019, 8:21pm UTC](https://forum.ansible.com/t/sending-mail-while-using-assert/31831/6 "2019-12-18T20:21:18Z")

</div>

Disregard…

thanks for your help Vlad!
