Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop the playbook if one play fails

I have the following playbook with 3 plays. When one of the plays fail, the next plays still execute. I think it is because I run those plays with a different host target.

I would like to avoid this and have the playbook stop when one play fails, is it possible?

---
- name: create the EC2 instances
  hosts: localhost
  any_errors_fatal: yes
  connection: local
  tasks:
    - ...

- name: configure instances
  hosts: appserver
  any_errors_fatal: yes
  gather_facts: true
  tasks:
   - ...

- name: Add to load balancer
  hosts: localhost
  any_errors_fatal: yes
  vars:
    component: travelmatrix
  tasks:
    - ...
like image 411
David Avatar asked Jun 21 '16 09:06

David


1 Answers

You can use any_errors_fatal which stops the play if there are any errors.


- name: create the EC2 instances
  hosts: localhost
  connection: local
  any_errors_fatal: true
  tasks:
   - ...

Reference Link

like image 179
Aarat Nathwani Avatar answered Nov 22 '22 09:11

Aarat Nathwani