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

RPL-37 Allow custom bin path on gather facts false #398

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 +23,7 @@
public class AnsibleInventoryList {

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

Expand All @@ -33,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 @@ -42,7 +45,11 @@ public class AnsibleInventoryList {
public String getNodeList() throws IOException, AnsibleException {

List<String> procArgs = new ArrayList<>();
procArgs.add(ANSIBLE_INVENTORY);
String ansibleCommand = ANSIBLE_INVENTORY_COMMAND;
if(ansibleBinariesDirectory!=null) {
ansibleCommand = Paths.get(ansibleBinariesDirectory.toFile().getAbsolutePath(), ansibleCommand).toFile().getAbsolutePath();
}
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 @@ -761,8 +761,14 @@ public String getNodesFromInventory(AnsibleRunner.AnsibleRunnerBuilder runnerBui
AnsibleRunner runner = runnerBuilder.build();

if (this.ansibleInventoryListBuilder == null) {
Path ansibleBinPath = null;
if (ansibleBinariesDirectoryPath != null && !ansibleBinariesDirectoryPath.isEmpty()) {
ansibleBinPath = (java.nio.file.Path.of(ansibleBinariesDirectoryPath));
}

this.ansibleInventoryListBuilder = AnsibleInventoryList.builder()
.inventory(inventory)
.ansibleBinariesDirectory(ansibleBinPath)
.configFile(configFile)
.debug(debug);
}
Expand Down
Loading