Skip to content

Small suggestion for Chapter 11 fail/assert remarks #191

Closed

Description

@pestophagous

Thank you for your highly useful and highly readable book on Ansible. I have dog-eared my copy extensively!

In Chapter 11 there is a section named "The fail and assert modules".

It currently says:

Both fail and assert, when triggered, will abort the playbook
run, and the only difference is in the simplicity of their usage.

I humbly suggest amending that to something like:

Both fail and assert, when triggered, will abort the playbook
run. The choice between these two is one of style and simplicity.

One subtle difference is that a 'fail' task will be reported as
'skipped' in the final recap statistics when the failure is not
triggered.

If your playbook contains a single 'fail' task that is happily
not triggered, the playbook results will contain:

PLAY RECAP *********************************************************************
default                    : .......(snip)....    skipped=1

If your playbook instead contains a single 'assert' task that is
happily not triggered, you will see "skipped=0" and the
individual task outcome will be:

TASK [my_assert] ****************************************
ok: [default] => {
    "changed": false,
    "msg": "All assertions passed"
}

This subtlety about "skipped" task count can be relevant in scenarios where one must audit and justify tasks that have been skipped.

Activity

  1. changed the title [-]Small suggestion for Chapter 11 fail/assert remarks (in response to "help improve this book")[/-] [+]Small suggestion for Chapter 11 fail/assert remarks[/+] on Dec 31, 2019
  2. geerlingguy commented on Dec 31, 2019

    @geerlingguy
    Owner

    That's a good point! Didn't even think about that use case, but that would be one case where it's probably best to use assert rather than fail.

  3. geerlingguy commented on Jul 25, 2020

    @geerlingguy
    Owner

    I have updated the book with something along the lines of your suggestion. Thanks for the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions