Skip to content

Commit e72aefa

Browse files
author
Alexander Abarca
committed
Added yaml data size parameter at model source
1 parent d3c74f9 commit e72aefa

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ public static String[] getValues() {
158158

159159
public static final String ANSIBLE_ENCRYPT_EXTRA_VARS = "ansible-encrypt-extra-vars";
160160

161+
String ANSIBLE_YAML_DATA_SIZE = "ansible-yaml-data-size";
162+
161163
public static Property PLAYBOOK_PATH_PROP = PropertyUtil.string(
162164
ANSIBLE_PLAYBOOK_PATH,
163165
"Playbook",
@@ -527,4 +529,13 @@ public static String[] getValues() {
527529
.title("Encrypt Extra Vars.")
528530
.description("Encrypt the value of the extra vars keys.")
529531
.build();
532+
533+
Property YAML_DATA_SIZE_PROP = PropertyBuilder.builder()
534+
.string(ANSIBLE_YAML_DATA_SIZE)
535+
.required(false)
536+
.title("Inventory Yaml Data Size")
537+
.description("Set the MB size (Default value is 10MB)"+
538+
" that the plugin can process with the yaml data response from Ansible."+
539+
" (This only applies when Gather Facts = No)")
540+
.build();
530541
}

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRun
7272

7373
private String inventory;
7474
private boolean gatherFacts;
75+
private Integer yamlDataSize;
7576
private boolean ignoreErrors = false;
7677
private String limit;
7778
private String ignoreTagPrefix;
@@ -167,6 +168,10 @@ public void configure(Properties configuration) throws ConfigurationException {
167168
gatherFacts = "true".equals(resolveProperty(AnsibleDescribable.ANSIBLE_GATHER_FACTS,null,configuration,executionDataContext));
168169
ignoreErrors = "true".equals(resolveProperty(AnsibleDescribable.ANSIBLE_IGNORE_ERRORS,null,configuration,executionDataContext));
169170

171+
yamlDataSize = getIntegerValue(
172+
resolveProperty(AnsibleDescribable.ANSIBLE_YAML_DATA_SIZE,"10", configuration, executionDataContext),
173+
AnsibleDescribable.ANSIBLE_YAML_DATA_SIZE);
174+
170175
limit = (String) resolveProperty(AnsibleDescribable.ANSIBLE_LIMIT,null,configuration,executionDataContext);
171176
ignoreTagPrefix = (String) resolveProperty(AnsibleDescribable.ANSIBLE_IGNORE_TAGS,null,configuration,executionDataContext);
172177

@@ -670,9 +675,11 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
670675
*/
671676
public void ansibleInventoryList(NodeSetImpl nodes, AnsibleRunner.AnsibleRunnerBuilder runnerBuilder) throws ResourceModelSourceException {
672677

678+
int codePointLimit = yamlDataSize * 1024 * 1024;
679+
673680
LoaderOptions snakeOptions = new LoaderOptions();
674681
// max inventory file size allowed to 10mb
675-
snakeOptions.setCodePointLimit(10_485_760);
682+
snakeOptions.setCodePointLimit(codePointLimit);
676683
Yaml yaml = new Yaml(new SafeConstructor(snakeOptions));
677684

678685
String listResp = getNodesFromInventory(runnerBuilder);
@@ -812,4 +819,23 @@ public List<String> listSecretsPathResourceModel(Map<String, Object> configurati
812819

813820
}
814821

822+
/**
823+
*
824+
* @param value parameter from gui
825+
* @param paramName parameter name
826+
* @return an integer value
827+
* @throws ConfigurationException
828+
*/
829+
private Integer getIntegerValue(String value, String paramName) throws ConfigurationException {
830+
if (value == null) {
831+
throw new ConfigurationException("Value cannot be null for parameter: " + paramName);
832+
}
833+
834+
try {
835+
return Integer.parseInt(value);
836+
} catch (NumberFormatException e) {
837+
throw new ConfigurationException("Error parsing " + paramName + " as integer: " + e.getMessage(), e);
838+
}
839+
}
840+
815841
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public AnsibleResourceModelSourceFactory(final Framework framework) {
3535
builder.property(INVENTORY_PROP);
3636
builder.property(CONFIG_FILE_PATH);
3737
builder.property(GATHER_FACTS_PROP);
38+
builder.property(YAML_DATA_SIZE_PROP);
3839
builder.property(IGNORE_ERRORS_PROP);
3940
builder.property(LIMIT_PROP);
4041
builder.property(DISABLE_LIMIT_PROP);

0 commit comments

Comments
 (0)