Jay Taylor's notes
back to listing indexIs there a way to block/rescue my entire playbook? • r/ansible
[web search]ansible
subscribe8,770 readers99 currently online
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 is an archived post. You won't be able to vote or comment.
Is there a way to block/rescue my entire playbook? (self.ansible)
submitted 8 months ago by brandononrails
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).
[–]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"
[–]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.