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"

======================================================

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?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/822788d3-c139-4327-aec2-012e2ef59732%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to