Skip to content

Commit

Permalink
Added max aliases option to snakeyaml and also added inventory yaml g…
Browse files Browse the repository at this point in the history
…roup with these snakeyaml fields
  • Loading branch information
alexander-variacode committed Oct 16, 2024
1 parent 56ef33a commit e67d6d0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.dtolabs.rundeck.plugins.util.PropertyBuilder;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

public interface AnsibleDescribable extends Describable {

Expand Down Expand Up @@ -90,6 +92,9 @@ public static String[] getValues() {
}
}

// General variables
String SECONDARY = "SECONDARY";

public static final String SERVICE_PROVIDER_TYPE = "ansible-service";
public static final String ANSIBLE_PLAYBOOK_PATH = "ansible-playbook";
public static final String ANSIBLE_PLAYBOOK_INLINE = "ansible-playbook-inline";
Expand Down Expand Up @@ -135,10 +140,6 @@ public static String[] getValues() {
public static final String ANSIBLE_SSH_PASSPHRASE_OPTION = "ansible-ssh-passphrase-option";
public static final String DEFAULT_ANSIBLE_SSH_PASSPHRASE_OPTION = "option.password";





// become configuration
public static final String ANSIBLE_BECOME = "ansible-become";
public static final String ANSIBLE_BECOME_USER = "ansible-become-user";
Expand All @@ -158,7 +159,14 @@ 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";
// Inventory Yaml
String ANSIBLE_YAML_DATA_SIZE = "ansible-yaml-data-size";
String ANSIBLE_YAML_MAX_ALIASES = "ansible-yaml-max-aliases";
String INVENTORY_YAML = "Inventory Yaml";
Map<String, Object> inventoryYamlOpt = Map.of(
StringRenderingConstants.GROUPING, SECONDARY,
StringRenderingConstants.GROUP_NAME, INVENTORY_YAML
);

public static Property PLAYBOOK_PATH_PROP = PropertyUtil.string(
ANSIBLE_PLAYBOOK_PATH,
Expand Down Expand Up @@ -533,9 +541,20 @@ public static String[] getValues() {
Property YAML_DATA_SIZE_PROP = PropertyBuilder.builder()
.integer(ANSIBLE_YAML_DATA_SIZE)
.required(false)
.title("Inventory Yaml Data Size")
.description("Set the MB size (Default value is 10)"+
" therefore, the plugin can process the yaml data response coming from Ansible."+
.title("Data Size")
.description("Set the MB size (Default value is 10)."+
" Allows the plugin to process the yaml data response coming from Ansible."+
" (This only applies when Gather Facts = No)")
.renderingOptions(inventoryYamlOpt)
.build();

Property YAML_MAX_ALIASES_PROP = PropertyBuilder.builder()
.integer(ANSIBLE_YAML_MAX_ALIASES)
.required(false)
.title("Max Aliases")
.description("Set max size (Default value is 1000)."+
" Allows to set the maximum number of aliases that the inventory can have."+
" (This only applies when Gather Facts = No)")
.renderingOptions(inventoryYamlOpt)
.build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -57,6 +56,7 @@
import java.util.Set;

import static com.rundeck.plugins.ansible.ansible.InventoryList.*;
import static com.rundeck.plugins.ansible.ansible.AnsibleDescribable.*;

public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRunnerPlugin {

Expand All @@ -77,8 +77,6 @@ public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRun

private String inventory;
private boolean gatherFacts;
@Setter
private Integer yamlDataSize;
private boolean ignoreErrors = false;
private String limit;
private String ignoreTagPrefix;
Expand Down Expand Up @@ -125,6 +123,11 @@ public class AnsibleResourceModelSource implements ResourceModelSource, ProxyRun

protected boolean encryptExtraVars = false;

@Setter
private Integer yamlDataSize;
@Setter
private Integer yamlMaxAliases;

@Setter
private AnsibleInventoryList.AnsibleInventoryListBuilder ansibleInventoryListBuilder = null;

Expand Down Expand Up @@ -185,8 +188,6 @@ 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 = resolveIntProperty(AnsibleDescribable.ANSIBLE_YAML_DATA_SIZE,10, configuration, executionDataContext);

limit = (String) resolveProperty(AnsibleDescribable.ANSIBLE_LIMIT,null,configuration,executionDataContext);
ignoreTagPrefix = (String) resolveProperty(AnsibleDescribable.ANSIBLE_IGNORE_TAGS,null,configuration,executionDataContext);

Expand Down Expand Up @@ -242,6 +243,10 @@ public void configure(Properties configuration) throws ConfigurationException {

encryptExtraVars = "true".equals(resolveProperty(AnsibleDescribable.ANSIBLE_ENCRYPT_EXTRA_VARS,"false",configuration,executionDataContext));

// Inventory Yaml
yamlDataSize = resolveIntProperty(ANSIBLE_YAML_DATA_SIZE,10, configuration, executionDataContext);
yamlMaxAliases = resolveIntProperty(ANSIBLE_YAML_MAX_ALIASES,1000, configuration, executionDataContext);

}

public AnsibleRunner.AnsibleRunnerBuilder buildAnsibleRunner() throws ResourceModelSourceException {
Expand Down Expand Up @@ -695,6 +700,8 @@ public void ansibleInventoryList(NodeSetImpl nodes, AnsibleRunner.AnsibleRunnerB
LoaderOptions snakeOptions = new LoaderOptions();
// max inventory file size allowed to 10mb
snakeOptions.setCodePointLimit(codePointLimit);
// max aliases. Default value is 1000
snakeOptions.setMaxAliasesForCollections(yamlMaxAliases);
Yaml yaml = new Yaml(new SafeConstructor(snakeOptions));

String listResp = getNodesFromInventory(runnerBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ 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);
Expand Down Expand Up @@ -64,6 +63,9 @@ public AnsibleResourceModelSourceFactory(final Framework framework) {
builder.property(SSH_USE_AGENT);
builder.property(BECOME_PASSWORD_STORAGE_PROP);

builder.property(YAML_DATA_SIZE_PROP);
builder.property(YAML_MAX_ALIASES_PROP);

builder.mapping(ANSIBLE_INVENTORY,PROJ_PROP_PREFIX + ANSIBLE_INVENTORY);
builder.frameworkMapping(ANSIBLE_INVENTORY,FWK_PROP_PREFIX + ANSIBLE_INVENTORY);
builder.mapping(ANSIBLE_CONFIG_FILE_PATH,PROJ_PROP_PREFIX + ANSIBLE_CONFIG_FILE_PATH);
Expand Down

0 comments on commit e67d6d0

Please sign in to comment.