Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible-runner: Fix getting status of playbook #468

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -61,12 +61,10 @@ public void doPolling(Guid cmdId, List<Guid> childCmdIds) {

AnsibleReturnValue ret = new AnsibleReturnValue(AnsibleReturnCode.ERROR);
ret.setLogFile(runnerClient.getLogger().getLogFile());
String msg = "";
int totalEvents;
// Get the current status of the playbook:
AnsibleRunnerClient.PlaybookStatus playbookStatus = runnerClient.getPlaybookStatus(playUuid);
String status = playbookStatus.getStatus();
msg = playbookStatus.getMsg();
String msg = playbookStatus.getMsg();
// Process the events if the playbook is running:
totalEvents = runnerClient.getTotalEvents(playUuid);

Expand All @@ -82,9 +80,6 @@ public void doPolling(Guid cmdId, List<Guid> childCmdIds) {
ret.setAnsibleReturnCode(AnsibleReturnCode.OK);
command.setSucceeded(true);
command.setCommandStatus(CommandStatus.SUCCEEDED);
} else if (status.equalsIgnoreCase("unknown")) {
// ignore and continue:
return;
} else {
// Playbook failed:
command.setSucceeded(false);
Expand Down
Expand Up @@ -265,14 +265,19 @@ protected String formatCommandVariables(Map<String, Object> variables, String pl
public PlaybookStatus getPlaybookStatus(String playUuid) {
String status = "";
String rc = "";
String privateRunDir = String.format("%1$s/%2$s/", AnsibleConstants.ANSIBLE_RUNNER_PATH, playUuid);
String playData = String.format("%1$s/%2$s/artifacts/%2$s/", AnsibleConstants.ANSIBLE_RUNNER_PATH, playUuid);
try {
if (!Files.exists(Paths.get(String.format("%1$s/status", playData)))) {
if (Files.exists(Paths.get(String.format("%1$s/status", playData)))) {
status = Files.readString(Paths.get(String.format("%1$s/status", playData)));
rc = Files.readString(Paths.get(String.format("%1$s/rc", playData)));
} else if (Files.exists(Paths.get(String.format("%1$s/daemon.log", privateRunDir)))) {
// artifacts are not yet present, try to fetch them in the next polling round
return new PlaybookStatus("unknown", "");
mnecas marked this conversation as resolved.
Show resolved Hide resolved
return new PlaybookStatus("", "running");
} else {
log.warn(String.format("The playbook failed with unknow error at: %1$s", playData));
return new PlaybookStatus("", "failed");
}
status = Files.readString(Paths.get(String.format("%1$s/status", playData)));
rc = Files.readString(Paths.get(String.format("%1$s/rc", playData)));
} catch (Exception e) {
throw new AnsibleRunnerCallException(
String.format("Failed to read playbook result at: %1$s", playData), e);
Expand Down