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 = null; AnsibleRunnerHTTPClient runnerClient = null; try { runnerClient = ansibleClientFactory.create(command); ret.setLogFile(runnerClient.getLogger().getLogFile()); playUuid = runnerClient.runPlaybook(command); 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 (runnerClient.isHostUnreachable(playUuid)) { ret.setAnsibleReturnCode(AnsibleReturnCode.UNREACHABLE); } 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 { if (playUuid != null && runnerClient != null) { 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 = null; AnsibleRunnerHTTPClient runnerClient = null; try { runnerClient = ansibleClientFactory.create(command); ret.setLogFile(runnerClient.getLogger().getLogFile()); playUuid = runnerClient.runPlaybook(command); if (runnerClient.isHostUnreachable(playUuid)) { ret.setAnsibleReturnCode(AnsibleReturnCode.UNREACHABLE); return ret; } 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 { if (playUuid != null && runnerClient != null) { runnerClient.processEvents(playUuid, lastEventId, fn); } } return ret; }