hello,
I have playbook that imports multiple sub play books. Basically, i want the main playbook to shut down the servers sequentially..
main play book:
---
- hosts: all
remote_user: test
become: yes
connection: ssh
gather_facts: false
#ignore_errors: no
#any_errors_fatal: true
tasks:
- import_tasks: first.yml
when: inventory_hostname in groups['ma_group']
- import_tasks: second.yml
when: inventory_hostname in groups['eg_group'] and
- import_tasks: third.yml
when: inventory_hostname in groups['si_group']
- pause: seconds=20
- import_tasks: fourth.yml
when: inventory_hostname in groups['ai_group']
==============================================================================
below are the sub playbooks:
first.yml
- name: execute stopbridges.sh
shell: /home/test/stopBridges.sh > /home/test/output.log
( The playbook logins to the first server, executes a script)
===============================================================================
second.yml
- name: execute stopEG.sh and shutdown
shell: /home/test/stopEG.sh
register: script_output
- debug:
var: script_output
- name: shutdown the server now
command: shutdown -h now
when: not script_output.failed
(logins to the second server if the script has a execute code of 1, it will not shutdown the server.)
==================================================================================
third.yml
- name: execute stopAI.sh and shutdown
shell: /home/test/stopAI.sh > /home/test/output1.log
register: result
- pause: seconds=10
- name: shutdown the server now
command: shutdown -h now
(login to the first server again and executes a different script and shuts down the server)
===================================================================================
fourth.yml
- name: execute stopAI.sh and shutdown
shell: /home/test/stopAI.sh > /home/test/output.log
register: result
- pause: seconds=10
- name: shutdown the server now
command: shutdown -h now
login to the third server, executes the script and shuts it down.
=====================================================================================
My issue is with the second.yml file i have an exit code of 1, i want the main playbook to be stopped at the end of second.yml but instead it is just skipping the shutdown in second.yml and shutting down the servers in third and fourth playbooks.
All i want is playbook to be stopped if there is an error and not shut the other servers down!
Please help me!