sending mail while using assert?

27 views
Skip to first unread message

evnflow

unread,
Dec 16, 2019, 4:01:18 PM12/16/19
to Ansible Project
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

Vladimir Botka

unread,
Dec 16, 2019, 4:30:25 PM12/16/19
to evnflow, ansible...@googlegroups.com
On Mon, 16 Dec 2019 13:01:18 -0800 (PST)
evnflow <vincent...@gmail.com> wrote:

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

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

- block:
- mail:
subject: Ansible disk usage report
to: ans...@master.example.com
body: |
Disk usage {{ disk_usage_ratio_s }}
exceeds {{ disk_limit_ratio_s }}
- meta: end_host
when: ((disk_usage|float)/mount.size_total) > disk_limit|float

Cheers,

-vlado

evnflow

unread,
Dec 18, 2019, 8:18:54 AM12/18/19
to Ansible Project
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? 

Vladimir Botka

unread,
Dec 18, 2019, 9:57:26 AM12/18/19
to evnflow, ansible...@googlegroups.com
On Wed, 18 Dec 2019 05:18:54 -0800 (PST)
evnflow <vincent...@gmail.com> wrote:

> 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?
> >
> > - block:
> > - mail:
> > subject: Ansible disk usage report
> > to: ans...@master.example.com <javascript:>
> > body: |
> > Disk usage {{ disk_usage_ratio_s }}
> > exceeds {{ disk_limit_ratio_s }}
> > - meta: end_host
> > when: ((disk_usage|float)/mount.size_total) > disk_limit|float

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

Why is that? Have you tested the condition?

Cheers,

-vlado

evnflow

unread,
Dec 18, 2019, 10:21:37 AM12/18/19
to Ansible Project
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%"

evnflow

unread,
Dec 18, 2019, 3:21:18 PM12/18/19
to Ansible Project

Disregard.. 

thanks for your help Vlad!

On Monday, December 16, 2019 at 4:30:25 PM UTC-5, Vladimir Botka wrote:
On Mon, 16 Dec 2019 13:01:18 -0800 (PST)

Reply all
Reply to author
Forward
0 new messages