Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ansible_ssh_pass rather than ansible_ssh_password + increase default limits on yaml + Fix null pointer issue(s) #388

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class BasicIntegrationSpec extends BaseTestConfiguration {
ansibleNodeExecutionStatus.get("failed")==0
ansibleNodeExecutionStatus.get("skipped")==0
ansibleNodeExecutionStatus.get("ignored")==0
logs.findAll {it.log.contains("encryptVariable ansible_ssh_password:")}.size() == 1
logs.findAll {it.log.contains("encryptVariable ansible_ssh_pass:")}.size() == 1
}

def "test simple inline playbook private-key with passphrase authentication"(){
Expand Down Expand Up @@ -301,7 +301,7 @@ class BasicIntegrationSpec extends BaseTestConfiguration {
ansibleNodeExecutionStatus.get("failed")==0
ansibleNodeExecutionStatus.get("skipped")==0
ansibleNodeExecutionStatus.get("ignored")==0
logs.findAll {it.log.contains("encryptVariable ansible_ssh_password:")}.size() == 1
logs.findAll {it.log.contains("encryptVariable ansible_ssh_pass:")}.size() == 1
logs.findAll {it.log.contains("\"environmentTest\": \"test\"")}.size() == 1
logs.findAll {it.log.contains("\"token\": 13231232312321321321321")}.size() == 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public int run() throws Exception {
}

if (sshUsePassword) {
String extraVarsPassword = "ansible_ssh_password: " + sshPass;
String extraVarsPassword = "ansible_ssh_pass: " + sshPass;
String finalextraVarsPassword = extraVarsPassword;

if(useAnsibleVault){
Expand Down Expand Up @@ -790,4 +790,4 @@ public String encryptExtraVarsKey(String extraVars) throws Exception {
return stringBuilder.toString();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ 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);
yamlDataSize = resolveIntProperty(AnsibleDescribable.ANSIBLE_YAML_DATA_SIZE,1000, 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 @@ -683,6 +683,55 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
}
}

private NodeSetImpl ansibleInventoryListAddNodes(NodeSetImpl nodes, Map<String, Object> all) throws ResourceModelSourceException {
//System.out.println("[DEBUG] all: " + all);
Map<String, Object> children = InventoryList.getValue(all, CHILDREN);

for (Map.Entry<String, Object> pair : children.entrySet()) {
String hostGroup = pair.getKey();
Map<String, Object> hostNames = InventoryList.getType(pair.getValue());
Map<String, Object> hosts = InventoryList.getValue(hostNames, HOSTS);
Map<String, Object> grandchildren = InventoryList.getValue(hostNames, CHILDREN);

if (grandchildren != null) {
//System.out.println("[DEBUG] pair: " + pair);
//System.out.println("[DEBUG] grandchildren: " + grandchildren);
nodes = ansibleInventoryListAddNodes(nodes,
Map.ofEntries(
Map.entry("children", grandchildren)
)
);
}
if (hosts != null) {
for (Map.Entry<String, Object> hostNode : hosts.entrySet()) {
NodeEntryImpl node = new NodeEntryImpl();
node.setTags(Set.of(hostGroup));
String hostName = hostNode.getKey();
node.setHostname(hostName);
node.setNodename(hostName);
Map<String, Object> nodeValues = InventoryList.getType(hostNode.getValue());

InventoryList.tagHandle(NodeTag.HOSTNAME, node, nodeValues);
InventoryList.tagHandle(NodeTag.USERNAME, node, nodeValues);
InventoryList.tagHandle(NodeTag.OS_FAMILY, node, nodeValues);
InventoryList.tagHandle(NodeTag.OS_NAME, node, nodeValues);
InventoryList.tagHandle(NodeTag.OS_ARCHITECTURE, node, nodeValues);
InventoryList.tagHandle(NodeTag.OS_VERSION, node, nodeValues);
InventoryList.tagHandle(NodeTag.DESCRIPTION, node, nodeValues);

nodeValues.forEach((key, value) -> {
if (value != null) {
node.setAttribute(key, value.toString());
}
});

nodes.putNode(node);
}
}
}
return nodes;
}

/**
* Process nodes coming from Ansible to convert them to Rundeck node
* @param nodes Rundeck nodes
Expand All @@ -693,12 +742,16 @@ public void ansibleInventoryList(NodeSetImpl nodes, AnsibleRunner.AnsibleRunnerB
int codePointLimit = yamlDataSize * 1024 * 1024;

LoaderOptions snakeOptions = new LoaderOptions();
// max inventory file size allowed to 10mb
// max inventory file size allowed to 1000mb
snakeOptions.setCodePointLimit(codePointLimit);
snakeOptions.setMaxAliasesForCollections(Integer.MAX_VALUE); // crazy large number for now
Yaml yaml = new Yaml(new SafeConstructor(snakeOptions));

String listResp = getNodesFromInventory(runnerBuilder);

//strip everything before all:
listResp = listResp.substring(listResp.indexOf("all:"));

Map<String, Object> allInventory;
try {
allInventory = yaml.load(listResp);
Expand All @@ -707,38 +760,7 @@ public void ansibleInventoryList(NodeSetImpl nodes, AnsibleRunner.AnsibleRunnerB
}

Map<String, Object> all = InventoryList.getValue(allInventory, ALL);
Map<String, Object> children = InventoryList.getValue(all, CHILDREN);

for (Map.Entry<String, Object> pair : children.entrySet()) {
String hostGroup = pair.getKey();
Map<String, Object> hostNames = InventoryList.getType(pair.getValue());
Map<String, Object> hosts = InventoryList.getValue(hostNames, HOSTS);

for (Map.Entry<String, Object> hostNode : hosts.entrySet()) {
NodeEntryImpl node = new NodeEntryImpl();
node.setTags(Set.of(hostGroup));
String hostName = hostNode.getKey();
node.setHostname(hostName);
node.setNodename(hostName);
Map<String, Object> nodeValues = InventoryList.getType(hostNode.getValue());

InventoryList.tagHandle(NodeTag.HOSTNAME, node, nodeValues);
InventoryList.tagHandle(NodeTag.USERNAME, node, nodeValues);
InventoryList.tagHandle(NodeTag.OS_FAMILY, node, nodeValues);
InventoryList.tagHandle(NodeTag.OS_NAME, node, nodeValues);
InventoryList.tagHandle(NodeTag.OS_ARCHITECTURE, node, nodeValues);
InventoryList.tagHandle(NodeTag.OS_VERSION, node, nodeValues);
InventoryList.tagHandle(NodeTag.DESCRIPTION, node, nodeValues);

nodeValues.forEach((key, value) -> {
if (value != null) {
node.setAttribute(key, value.toString());
}
});

nodes.putNode(node);
}
}
nodes = ansibleInventoryListAddNodes(nodes, all);
}

/**
Expand Down