'Ansible Run second playbook only if the first one is done correctly

I’ll tell you about my scenario. I have a host file with two servers and two playbooks.

I need to perform the following, first I have to run a playbook on server number 1 and if there is no errors, I need to run the second playbook on server number 2. What condition should I use?

 - name: Execute the First Play
   import_playbook: first-playbook-to-run.yml

 - name: Run the Second Playbook
   import_playbook: second-playbook-to-run.yml

Any helps? Regards,



Solution 1:[1]

Try the below

- name: Execute the First Play
  import_playbook: first-playbook-to-run.yml
  delegate_to: server1
  run_once: true

- name: Run the Second Playbook
  import_playbook: second-playbook-to-run.yml
  delegate_to: server2
  run_once: true

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KrishnaR