I am trying to execute a shut down script and Shut down remote server upon successful execution of the script . I do not want to shutdown the server when the script fails.
I did write the play book below, but it is throwing errors. can some one help me on this?
- hosts: all
user: test
become: yes
connection: ssh
gather_facts: false
ignore_errors: yes
tasks:
- name: execute stop.sh script
shell: /home/test/stop.sh
register: script_output
- debug:
var: script_output
- name: shutdown the server
command: shutdown -h now
when: "script_output.rc !=0"