- 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"
======================================================
here is the output for script_output
"script_output": {
"changed": true,
"cmd": "/home/test/stop.sh",
"delta": "0:00:00.004297",
"end": "2018-10-23 18:15:13.564368",
"failed": true,
"msg": "non-zero return code",
"rc": 1,
"start": "2018-10-23 18:15:13.560071",
"stderr": "",
"stderr_lines": [],
"stdout": "hello world",
"stdout_lines": [
"hello world"
]
}
}
========================================
below is the error
fatal: [10.x.x.x]: FAILED! => {"msg": "The conditional check 'script_output.find('rc'') != 0' failed. The error was: template error while templating string: unexpected char u\"'\" at 29. String: {% if script_output.find('rc'') != 0 %} True {% else %} False {% endif %}\n\nThe error appears to have been in '/home/vadsit01/playbooks/include/errorhandling/error.yml': line 17, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: shutdown\n ^ here\n"}
can some one help me with it please?
when: "scrtipt_output.rc !=0"
The error was: template error while templating string: unexpected char u\"'\" at 29