# Diffculty with registering the script output

**URL:** <https://forum.ansible.com/t/diffculty-with-registering-the-script-output/28856>\
**Category:** Ansible Project\
**Created:** [October 24, 2018, 2:23am UTC](https://forum.ansible.com/t/diffculty-with-registering-the-script-output/28856 "2018-10-24T02:23:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![itssitaram9](https://avatars.discourse-cdn.com/v4/letter/i/4bbf92/32.png) [@itssitaram9](https://forum.ansible.com/u/itssitaram9)\
**Post date:** [October 24, 2018, 2:23am UTC](https://forum.ansible.com/t/diffculty-with-registering-the-script-output/28856/1 "2018-10-24T02:23:27Z")

</div>

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  
&nbsp;&nbsp;user: test  
&nbsp;&nbsp;become: yes  
&nbsp;&nbsp;connection: ssh  
&nbsp;&nbsp;gather\_facts: false  
&nbsp;&nbsp;ignore\_errors: yes

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: execute stop.sh script  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: /home/test/stop.sh  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: script\_output  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: script\_output  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;- name: shutdown the server  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: shutdown -h now  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: "script\_output.rc !=0"

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 24, 2018, 5:21am UTC](https://forum.ansible.com/t/diffculty-with-registering-the-script-output/28856/2 "2018-10-24T05:21:46Z")

</div>

Remove the quotation marks. The conditionals are expanded automatically.

> when: “scrtipt\_output.rc !=0”

…

> The error was: template error while templating string: unexpected char u"'" at 29

Alternatively you might want to use:

when: not scrtipt\_output.failed

---

<div class="post-metadata">

**Author:** ![itssitaram9](https://avatars.discourse-cdn.com/v4/letter/i/4bbf92/32.png) [@itssitaram9](https://forum.ansible.com/u/itssitaram9)\
**Post date:** [October 24, 2018, 1:30pm UTC](https://forum.ansible.com/t/diffculty-with-registering-the-script-output/28856/3 "2018-10-24T13:30:13Z")

</div>

Thanks alot!  
when: not scrtipt\_output.failed

**This is worked for me!!!**
