Skip to content

Commit

Permalink
ansible: do not raise on missing host
Browse files Browse the repository at this point in the history
Upgrade Cluster role is run locally on engine, "host" is not defined.
Do not raise on that.

This reverts f7561f9
  • Loading branch information
michalskrivanek authored and mrkev-gh committed Aug 16, 2022
1 parent fb7f1eb commit 52f06b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,11 @@ private void createHostFile(File inventory) {
File hostFile = new File(String.format("%1$s/hosts", inventory));
try {
hostFile.createNewFile();
Files.write(hostFile.toPath(),
String.format(this.host.getHostName() + " ansible_port=%1$s", this.host.getSshPort()).getBytes());
if (host != null) {
// if VDS is null then playbook is running on engine and ansible uses localhost inventory automatically
Files.write(hostFile.toPath(),
String.format(this.host.getHostName() + " ansible_port=%1$s", this.host.getSshPort()).getBytes());
}
} catch (IOException ex) {
throw new AnsibleRunnerCallException(
String.format("Failed to create inventory file '%s':", hostFile.toString()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ public AnsibleReturnValue runCommand(AnsibleCommandConfig command,
}

public AnsibleReturnValue runCommand(AnsibleCommandConfig commandConfig, int timeout, BiConsumer<String, String> fn, boolean async) {
if (commandConfig.host() == null) {
throw new AnsibleRunnerCallException("Invalid host");
}
if (timeout <= 0) {
timeout = EngineLocalConfig.getInstance().getInteger("ANSIBLE_PLAYBOOK_EXEC_DEFAULT_TIMEOUT");
}
Expand Down Expand Up @@ -198,6 +195,12 @@ public AnsibleReturnValue runCommand(AnsibleCommandConfig commandConfig, int tim
}

private AuditLogable createAuditLogable(AnsibleCommandConfig command, String taskName) {
if (command.host() == null) {
return AuditLogableImpl.createEvent(
command.correlationId(),
Map.of("Message", taskName, "PlayAction", command.playAction())
);
}
return AuditLogableImpl.createHostEvent(
command.host(),
command.correlationId(),
Expand Down

0 comments on commit 52f06b2

Please sign in to comment.