sending mail while using assert?

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

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

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?

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

Why is that? Have you tested the condition?

Cheers,

  -vlado

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

Disregard…

thanks for your help Vlad!