0

I want to include a playbook in the master playbook. However if anything fails in the include playbooks, master playbook should exit out without running further tasks specified in it.

MasterPlaybook.yml

    - include: playbook1.yml
    - include: playbook2.yml

    - name: copy file
      shell: echo "hello"

    - name: list other one
      shell: echo "Hi"

playbook1.yml

  - name: list task
    shell: ls /tmp/ | grep text.html


   - name: list file 
     shell: ls /root/ | grep text2.html

playbook2.yml

   - name: list task
     shell: ls /tmp/ | grep text.html


   - name: list file 
     shell: ls /root/ | grep text2.html

So in the above example if any task fail in playbook1.yml, the rest of the tasks in master should not get executed

DevOps Learner
  • 97
  • 1
  • 2
  • 6

1 Answers1

2

For playbooks you can use any_errors_fatal: yes.

For tasks you can use rescue block meta: end_play.

Update:

You have list of tasks, and not a playbook. So your filenames are misleading.

Anyway, you may want something like this:

- hosts: all
  tasks:
    - block:
        - include_tasks: file1.yml
      rescue:
        - meta: end_play
    - include_tasks: file2.yml
    - shell: echo ok

In this case if any task in file1.yml fails, meta: end_play will fire to stop playbook right away.

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193