assert vs fail

639 views
Skip to first unread message

S C Rigler

unread,
Jul 12, 2019, 11:12:47 AM7/12/19
to ansible...@googlegroups.com
Is there any advantage to using the assert module vs the fail module to bail out of a play if an expected condition isn't met?

Kai Stian Olstad

unread,
Jul 12, 2019, 11:21:57 AM7/12/19
to ansible...@googlegroups.com
On 12.07.2019 17:12, S C Rigler wrote:
> Is there any advantage to using the assert module vs the fail module to
> bail out of a play if an expected condition isn't met?

The outcome is the same, but they work opposite way

- fail:
msg="Hello"
when: myvar == True

- assert:
that: myvar == True

If myvar is True the fail will stop the play and the assert will continue the play.
And if myvar is False the opposite will happen.

--
Kai Stian Olstad

Hugo Gonzalez

unread,
Jul 12, 2019, 12:10:56 PM7/12/19
to ansible...@googlegroups.com

Hi,

On 7/12/19 10:12 AM, S C Rigler wrote:
Is there any advantage to using the assert module vs the fail module to bail out of a play if an expected condition isn't met?

I don think there's a technical advantage, but the concepts are different:

* use assert for checking against abnormal conditions, like a malformed or missing input, missing file, that should never happen in the normal flow of your playbook.

 * use fail for aborting the playbook on operations that can meaningfully fail and that you have an idea what's happening


--
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.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAFbiokc40fUQbzJ1J-5XKtWDZenCmYK35mWwBeUaW6OZ0qObvQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--

Hugo F. González

Senior Automation Consultant

Red Hat LATAM

hgon...@redhat.com   

Reply all
Reply to author
Forward
0 new messages