Skip to content

Commit

Permalink
improve how to obtain ansible bin path
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus-Osuna-M committed Oct 29, 2024
1 parent c87715a commit 17ce4c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -21,7 +23,7 @@
public class AnsibleInventoryList {

private String inventory;
private String ansibleBinariesDirectoryPath;
private Path ansibleBinariesDirectory;
private String configFile;
private boolean debug;

Expand All @@ -34,7 +36,7 @@ public class AnsibleInventoryList {
private File vaultPromptFile;
private File tempLimitFile;

public static final String ANSIBLE_INVENTORY = "ansible-inventory";
public static final String ANSIBLE_INVENTORY_COMMAND = "ansible-inventory";

/**
* Executes Ansible command to bring all nodes from inventory
Expand All @@ -43,10 +45,11 @@ public class AnsibleInventoryList {
public String getNodeList() throws IOException, AnsibleException {

List<String> procArgs = new ArrayList<>();
if(ansibleBinariesDirectoryPath!=null && !ansibleBinariesDirectoryPath.isEmpty()) {
procArgs.add(ansibleBinariesDirectoryPath+"/"+ANSIBLE_INVENTORY);
String ansibleCommand = ANSIBLE_INVENTORY_COMMAND;
if(ansibleBinariesDirectory!=null) {
ansibleCommand = Paths.get(ansibleBinariesDirectory.toFile().getAbsolutePath(), ansibleCommand).toFile().getAbsolutePath();
}
procArgs.add(ANSIBLE_INVENTORY);
procArgs.add(ansibleCommand);
//inventory can be defined in ansible.cfg
if(inventory!=null && !inventory.isEmpty()){
procArgs.add("--inventory-file" + "=" + inventory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ public String getNodesFromInventory(AnsibleRunner.AnsibleRunnerBuilder runnerBui
if (this.ansibleInventoryListBuilder == null) {
this.ansibleInventoryListBuilder = AnsibleInventoryList.builder()
.inventory(inventory)
.ansibleBinariesDirectoryPath(ansibleBinariesDirectoryPath)
.ansibleBinariesDirectory(java.nio.file.Path.of(ansibleBinariesDirectoryPath))
.configFile(configFile)
.debug(debug);
}
Expand Down

0 comments on commit 17ce4c4

Please sign in to comment.