Source:
public AnsibleReturnValue runCommand(AnsibleCommandConfig command, int timeout, BiConsumer<String, String> fn) { if (timeout <= 0) { timeout = EngineLocalConfig.getInstance().getInteger("ANSIBLE_PLAYBOOK_EXEC_DEFAULT_TIMEOUT"); } log.trace("Enter AnsibleExecutor::runCommand"); AnsibleReturnValue ret = new AnsibleReturnValue(AnsibleReturnCode.ERROR); int lastEventId = 0; int iteration = 0; int totalEvents; String playUuid = runnerClient.runPlaybook(command); AnsibleRunnerLogger runnerLogger = ansibleCommandLogFileFactory.create(command); runnerClient.setLogger(runnerLogger); ret.setLogFile(runnerLogger.getLogFile()); try { while (iteration < timeout * 60) { Thread.sleep(POLL_INTERVAL); AnsibleRunnerHTTPClient.PlaybookStatus playbookStatus = runnerClient.getPlaybookStatus(playUuid); String status = playbookStatus.getStatus(); String msg = playbookStatus.getMsg(); totalEvents = runnerClient.getTotalEvents(playUuid); if ( msg.equalsIgnoreCase("running") || (msg.equalsIgnoreCase("successful") && lastEventId < totalEvents) ) { lastEventId = runnerClient.processEvents(playUuid, lastEventId, fn); iteration += POLL_INTERVAL / 1000; } else if (msg.equalsIgnoreCase("successful")) { ret.setAnsibleReturnCode(AnsibleReturnCode.OK); return ret; } else if (status.equalsIgnoreCase("unknown")) { } else { return ret; } } runnerClient.cancelPlaybook(playUuid); throw new PlaybookExecutionException( "Timeout exceed while waiting for playbook. ", command.playbook() ); } catch (Exception ex) { log.error("Exception: {}", ex.getMessage()); log.debug("Exception: ", ex); ret.setStderr(ex.getMessage()); } finally { runnerClient.processEvents(playUuid, lastEventId, fn); } return ret; }

Target:
public AnsibleReturnValue runCommand(AnsibleCommandConfig command, int timeout, BiConsumer<String, String> fn) { if (timeout <= 0) { timeout = EngineLocalConfig.getInstance().getInteger("ANSIBLE_PLAYBOOK_EXEC_DEFAULT_TIMEOUT"); } log.trace("Enter AnsibleExecutor::runCommand"); AnsibleReturnValue ret = new AnsibleReturnValue(AnsibleReturnCode.ERROR); int lastEventId = 0; int iteration = 0; int totalEvents; String playUuid = runnerClient.runPlaybook(command); try { AnsibleRunnerLogger runnerLogger = ansibleCommandLogFileFactory.create(command); runnerClient.setLogger(runnerLogger); ret.setLogFile(runnerLogger.getLogFile()); while (iteration < timeout * 60) { Thread.sleep(POLL_INTERVAL); AnsibleRunnerHTTPClient.PlaybookStatus playbookStatus = runnerClient.getPlaybookStatus(playUuid); String status = playbookStatus.getStatus(); String msg = playbookStatus.getMsg(); totalEvents = runnerClient.getTotalEvents(playUuid); if ( msg.equalsIgnoreCase("running") || (msg.equalsIgnoreCase("successful") && lastEventId < totalEvents) ) { lastEventId = runnerClient.processEvents(playUuid, lastEventId, fn); iteration += POLL_INTERVAL / 1000; } else if (msg.equalsIgnoreCase("successful")) { ret.setAnsibleReturnCode(AnsibleReturnCode.OK); return ret; } else if (status.equalsIgnoreCase("unknown")) { } else { return ret; } } runnerClient.cancelPlaybook(playUuid); throw new PlaybookExecutionException( "Timeout exceed while waiting for playbook. ", command.playbook() ); } catch (Exception ex) { log.error("Exception: {}", ex.getMessage()); log.debug("Exception: ", ex); ret.setStderr(ex.getMessage()); } finally { runnerClient.processEvents(playUuid, lastEventId, fn); } return ret; }