diff --git a/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleInventoryList.java b/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleInventoryList.java index 84394a1..c3ea871 100644 --- a/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleInventoryList.java +++ b/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleInventoryList.java @@ -26,9 +26,12 @@ public class AnsibleInventoryList { private AnsibleVault ansibleVault; private VaultPrompt vaultPrompt; + private List limits; + private File tempInternalVaultFile; private File tempVaultFile; private File vaultPromptFile; + private File tempLimitFile; public static final String ANSIBLE_INVENTORY = "ansible-inventory"; @@ -55,6 +58,7 @@ public String getNodeList() throws Exception { List stdinVariables = new ArrayList<>(); processAnsibleVault(stdinVariables, procArgs); + processLimit(procArgs); if(debug){ System.out.println("getNodeList " + procArgs); @@ -115,4 +119,21 @@ private void processAnsibleVault(List stdinVariables, List procArgs.add(tempVaultFile.getAbsolutePath()); } } + + private void processLimit(List procArgs) throws IOException { + if (limits != null && limits.size() == 1) { + procArgs.add("-l"); + procArgs.add(limits.get(0)); + + } else if (limits != null && limits.size() > 1) { + StringBuilder sb = new StringBuilder(); + for (String limit : limits) { + sb.append(limit).append("\n"); + } + tempLimitFile = AnsibleUtil.createTemporaryFile("targets", sb.toString()); + + procArgs.add("-l"); + procArgs.add("@" + tempLimitFile.getAbsolutePath()); + } + } } diff --git a/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java b/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java index 5b857d1..b323906 100644 --- a/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java +++ b/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java @@ -723,6 +723,10 @@ public String getNodesFromInventory(AnsibleRunner.AnsibleRunnerBuilder runnerBui ansibleInventoryListBuilder.vaultPrompt(vaultPrompt); } + if (!runner.getLimits().isEmpty()) { + ansibleInventoryListBuilder.limits(runner.getLimits()); + } + AnsibleInventoryList inventoryList = this.ansibleInventoryListBuilder.build(); try {