It happens because when ansible close it’s ssh connection, and when the ssh connection is closed the kernel sends SIGHUP to the controlling process of the ssh connection. But when execution, the java process will receive the SIGHUP and will be terminated.

To avoid this you can use nohup, as it’s name implies it, nohup is a wrapper that will ignore SIGHUP signals for the process launched with nohup.

Example of use:

nohup tomcat/bin/ &