Skip to content

Commit 9ed488a

Browse files
Merge pull request #398 from rundeck-plugins/RPL-37-ansible-resource-model-crashes-when-ansible-binaries-are-not-in-the-system-path
RPL-37 Allow custom bin path on gather facts false
2 parents cd91466 + 1beb496 commit 9ed488a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleInventoryList.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.io.IOException;
1212
import java.io.InputStream;
1313
import java.io.InputStreamReader;
14+
import java.nio.file.Path;
15+
import java.nio.file.Paths;
1416
import java.util.ArrayList;
1517
import java.util.HashMap;
1618
import java.util.List;
@@ -21,6 +23,7 @@
2123
public class AnsibleInventoryList {
2224

2325
private String inventory;
26+
private Path ansibleBinariesDirectory;
2427
private String configFile;
2528
private boolean debug;
2629

@@ -33,7 +36,7 @@ public class AnsibleInventoryList {
3336
private File vaultPromptFile;
3437
private File tempLimitFile;
3538

36-
public static final String ANSIBLE_INVENTORY = "ansible-inventory";
39+
public static final String ANSIBLE_INVENTORY_COMMAND = "ansible-inventory";
3740

3841
/**
3942
* Executes Ansible command to bring all nodes from inventory
@@ -42,7 +45,11 @@ public class AnsibleInventoryList {
4245
public String getNodeList() throws IOException, AnsibleException {
4346

4447
List<String> procArgs = new ArrayList<>();
45-
procArgs.add(ANSIBLE_INVENTORY);
48+
String ansibleCommand = ANSIBLE_INVENTORY_COMMAND;
49+
if(ansibleBinariesDirectory!=null) {
50+
ansibleCommand = Paths.get(ansibleBinariesDirectory.toFile().getAbsolutePath(), ansibleCommand).toFile().getAbsolutePath();
51+
}
52+
procArgs.add(ansibleCommand);
4653
//inventory can be defined in ansible.cfg
4754
if(inventory!=null && !inventory.isEmpty()){
4855
procArgs.add("--inventory-file" + "=" + inventory);

src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java

+6
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,14 @@ public String getNodesFromInventory(AnsibleRunner.AnsibleRunnerBuilder runnerBui
761761
AnsibleRunner runner = runnerBuilder.build();
762762

763763
if (this.ansibleInventoryListBuilder == null) {
764+
Path ansibleBinPath = null;
765+
if (ansibleBinariesDirectoryPath != null && !ansibleBinariesDirectoryPath.isEmpty()) {
766+
ansibleBinPath = (java.nio.file.Path.of(ansibleBinariesDirectoryPath));
767+
}
768+
764769
this.ansibleInventoryListBuilder = AnsibleInventoryList.builder()
765770
.inventory(inventory)
771+
.ansibleBinariesDirectory(ansibleBinPath)
766772
.configFile(configFile)
767773
.debug(debug);
768774
}

0 commit comments

Comments
 (0)