1

I would like to get the correct return code from the called batch file so that my Ansible task fails if the batch call fails.

This seems to be impossible. Executing the given command directly in the CMD works and %errorlevel% is != 0. Executing it within Ansible rc is always "0" - except if the executable of the command is not found...

Any idea?

- name: undeploy ...
  win_shell: "set nopause=true && F:/xyz/wildfly-8.2.0.Final/bin/jboss-cli.bat --connect controller=myhost.net --user="myuser" --password="verysecret" --command=\"deploy F:\warfolder\mywar.war --server-groups=main-server-group\""
  args:
    executable: cmd
halfer
  • 19,824
  • 17
  • 99
  • 186
eventhorizon
  • 2,977
  • 8
  • 33
  • 57

1 Answers1

0

I have to change this:

- name: undeploy ...
  win_shell: "set nopause=true && F:/xyz/wildfly-8.2.0.Final/bin/jboss-cli.bat --connect controller=myhost.net --user="myuser" --password="verysecret" --command=\"deploy F:\warfolder\mywar.war --server-groups=main-server-group\""
  args:
    executable: cmd

to that:

- name: undeploy ...
  win_shell: "call set nopause=true && call F:/xyz/wildfly-8.2.0.Final/bin/jboss-cli.bat --connect controller=myhost.net --user="myuser" --password="verysecret" --command=\"deploy F:\warfolder\mywar.war --server-groups=main-server-group\""
  args:
    executable: cmd

I had to "call" everything.

Something that helped me: Difference between call and cmd /c in windows batch

halfer
  • 19,824
  • 17
  • 99
  • 186
eventhorizon
  • 2,977
  • 8
  • 33
  • 57