using assert in ansible

211 views
Skip to first unread message

evnflow

unread,
Dec 10, 2019, 10:30:04 AM12/10/19
to Ansible Project
I have a playbook and I am using the following assertion 

  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

My question is how do I register the output of   that: ( (disk_usage|float)/mount.size_total ) < disk_limit|float  

I would like to register the output so I can send email when I do not get the desired result. Any advice would be appreciated.

Stefan Hornburg (Racke)

unread,
Dec 10, 2019, 10:36:46 AM12/10/19
to ansible...@googlegroups.com
On 12/10/19 4:30 PM, evnflow wrote:
> I have a playbook and I am using the following assertion 
>
>   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
>
> My question is how do I register the output of   *that: ( (disk_usage|float)/mount.size_total ) < disk_limit|float  *
>
> I would like to register the output so I can send email when I do not get the desired result. Any advice would be
> appreciated.

I would run a "set_fact" task before the "assert" task which captures the output of your expression.

Regards
Racke

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7256dd01-1c2a-4fff-989f-0f34e4df22b7%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7256dd01-1c2a-4fff-989f-0f34e4df22b7%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

evnflow

unread,
Dec 10, 2019, 2:57:58 PM12/10/19
to Ansible Project
Thanks for the reply! having issues setting the "set_fact" the correct way.


On Tuesday, December 10, 2019 at 10:36:46 AM UTC-5, Stefan Hornburg (Racke) wrote:
On 12/10/19 4:30 PM, evnflow wrote:
> I have a playbook and I am using the following assertion 
>
>   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
>
> My question is how do I register the output of   *that: ( (disk_usage|float)/mount.size_total ) < disk_limit|float  *
>
> I would like to register the output so I can send email when I do not get the desired result. Any advice would be
> appreciated.

I would run a "set_fact" task before the "assert" task which captures the output of your expression.

Regards
         Racke

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
Reply all
Reply to author
Forward
0 new messages