From e72aefa72b4643f9341059a4366cb16ed2cfc5b7 Mon Sep 17 00:00:00 2001 From: Alexander Abarca Date: Mon, 15 Jul 2024 14:18:18 -0400 Subject: [PATCH] Added yaml data size parameter at model source --- .../ansible/ansible/AnsibleDescribable.java | 11 ++++++++ .../plugin/AnsibleResourceModelSource.java | 28 ++++++++++++++++++- .../AnsibleResourceModelSourceFactory.java | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleDescribable.java b/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleDescribable.java index fb80c3be..14987a74 100644 --- a/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleDescribable.java +++ b/src/main/groovy/com/rundeck/plugins/ansible/ansible/AnsibleDescribable.java @@ -158,6 +158,8 @@ public static String[] getValues() { public static final String ANSIBLE_ENCRYPT_EXTRA_VARS = "ansible-encrypt-extra-vars"; + String ANSIBLE_YAML_DATA_SIZE = "ansible-yaml-data-size"; + public static Property PLAYBOOK_PATH_PROP = PropertyUtil.string( ANSIBLE_PLAYBOOK_PATH, "Playbook", @@ -527,4 +529,13 @@ public static String[] getValues() { .title("Encrypt Extra Vars.") .description("Encrypt the value of the extra vars keys.") .build(); + + Property YAML_DATA_SIZE_PROP = PropertyBuilder.builder() + .string(ANSIBLE_YAML_DATA_SIZE) + .required(false) + .title("Inventory Yaml Data Size") + .description("Set the MB size (Default value is 10MB)"+ + " that the plugin can process with the yaml data response from Ansible."+ + " (This only applies when Gather Facts = No)") + .build(); } 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 ecbb5acc..92ab7ba4 100644 --- a/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java +++ b/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSource.java @@ -72,6 +72,7 @@ public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRun private String inventory; private boolean gatherFacts; + private Integer yamlDataSize; private boolean ignoreErrors = false; private String limit; private String ignoreTagPrefix; @@ -167,6 +168,10 @@ public void configure(Properties configuration) throws ConfigurationException { gatherFacts = "true".equals(resolveProperty(AnsibleDescribable.ANSIBLE_GATHER_FACTS,null,configuration,executionDataContext)); ignoreErrors = "true".equals(resolveProperty(AnsibleDescribable.ANSIBLE_IGNORE_ERRORS,null,configuration,executionDataContext)); + yamlDataSize = getIntegerValue( + resolveProperty(AnsibleDescribable.ANSIBLE_YAML_DATA_SIZE,"10", configuration, executionDataContext), + AnsibleDescribable.ANSIBLE_YAML_DATA_SIZE); + limit = (String) resolveProperty(AnsibleDescribable.ANSIBLE_LIMIT,null,configuration,executionDataContext); ignoreTagPrefix = (String) resolveProperty(AnsibleDescribable.ANSIBLE_IGNORE_TAGS,null,configuration,executionDataContext); @@ -670,9 +675,11 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx */ public void ansibleInventoryList(NodeSetImpl nodes, AnsibleRunner.AnsibleRunnerBuilder runnerBuilder) throws ResourceModelSourceException { + int codePointLimit = yamlDataSize * 1024 * 1024; + LoaderOptions snakeOptions = new LoaderOptions(); // max inventory file size allowed to 10mb - snakeOptions.setCodePointLimit(10_485_760); + snakeOptions.setCodePointLimit(codePointLimit); Yaml yaml = new Yaml(new SafeConstructor(snakeOptions)); String listResp = getNodesFromInventory(runnerBuilder); @@ -812,4 +819,23 @@ public List listSecretsPathResourceModel(Map configurati } + /** + * + * @param value parameter from gui + * @param paramName parameter name + * @return an integer value + * @throws ConfigurationException + */ + private Integer getIntegerValue(String value, String paramName) throws ConfigurationException { + if (value == null) { + throw new ConfigurationException("Value cannot be null for parameter: " + paramName); + } + + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + throw new ConfigurationException("Error parsing " + paramName + " as integer: " + e.getMessage(), e); + } + } + } diff --git a/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSourceFactory.java b/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSourceFactory.java index adaa30ea..0f94e79d 100644 --- a/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSourceFactory.java +++ b/src/main/groovy/com/rundeck/plugins/ansible/plugin/AnsibleResourceModelSourceFactory.java @@ -35,6 +35,7 @@ public AnsibleResourceModelSourceFactory(final Framework framework) { builder.property(INVENTORY_PROP); builder.property(CONFIG_FILE_PATH); builder.property(GATHER_FACTS_PROP); + builder.property(YAML_DATA_SIZE_PROP); builder.property(IGNORE_ERRORS_PROP); builder.property(LIMIT_PROP); builder.property(DISABLE_LIMIT_PROP);