back to listing index

Is there a way to block/rescue my entire playbook? • r/ansible

[web search]
Original source (www.reddit.com)
Tags: howto ansible failure recovery resiliency
Clipped on: 2018-06-28
this post was submitted on 05 Oct 2017
5 points (79% upvoted)
shortlink:
Subreddit Info

ansible

subscribe8,770 readers

99 currently online

Show my flair on this subreddit. It looks like:

Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.

This subreddit uses the /r/Naut theme.

This is an archived post. You won't be able to vote or comment.

5
For content that does not contribute to any discussion.

I just want to run the slack module if my playbook fails. Right now I have it reporting that a deployment starts and finishes successfully.

I learned I can wrap tasks in block/rescue, but I've got 3 roles and each role is broken down to a few includes (like my webserver role has dependencies, configuration, ssl, etc all broken up).

all 3 comments
sorted by:
best

For content that does not contribute to any discussion.

[–]dms_ 8 points 8 months ago 

The way we do this is to use the 'include_role' task instead of the 'roles' directive. Since 'include_role' is a task, you can properly wrap it in a block/rescue/always like so:

- name: Run tests
  hosts: nodes
  force_handlers: True
  tasks:
    - block:
        - include_role:
            name: "run-tests"
        - include_role:
            name: "logs"
            tasks_from: "recover"
      rescue:
        - include_role:
            name: "logs"
            tasks_from: "recover"
        - name: Failure detected in run-tests role
          fail:
            msg: "Failure detected in run-tests role"

For content that does not contribute to any discussion.

[–]senorsmile 2 points 8 months ago 

This is quite brilliant!

NB: Only compatible with 2.3.x+.

For content that does not contribute to any discussion.

[–]Robinsondan87 2 points 8 months ago 

I would also like to know how to do this; We are using ansible to create a VM shell and deploy Linux/Windows Servers.

If any of the Tasks fail we just want a cleanup script to run to remove the VM, AD accounts and DNS entries We already do this but it has to be done on a role-by-role basis would be nice if i can just wrap this around my entire playbook.

Use of this site constitutes acceptance of our User Agreement and Privacy Policy. © 2018 reddit inc. All rights reserved.

REDDIT and the ALIEN Logo are registered trademarks of reddit inc.