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

RPL-29: Fix - Ansible YAML parsing error #399

Merged
merged 2 commits into from
Nov 5, 2024
Merged
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
34 changes: 34 additions & 0 deletions functional-test/src/test/groovy/functional/YamlParsingSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package functional

import functional.base.BaseTestConfiguration
import org.testcontainers.spock.Testcontainers

@Testcontainers
class YamlParsingSpec extends BaseTestConfiguration {

static String PROJ_NAME = 'ansible-yaml-parsing'
static String NODE_1 = 'server1'
static String NODE_2 = 'server2'

def setupSpec() {
startCompose()
configureRundeck(PROJ_NAME, 'server1')
}

void "hide warnings"() {
when:
def result = client.apiCall {api-> api.listNodes(PROJ_NAME,'.*')}

then:
result != null
result.size() == 3
result.get(NODE_1) != null
result.get(NODE_1).getAttributes().get("ansible_host") == "192.168.1.10"
result.get(NODE_1).getAttributes().get("ansible_user") == "user2"
result.get(NODE_1).getAttributes().get("http_port") == "8080"
result.get(NODE_2) != null
result.get(NODE_2).getAttributes().get("ansible_host") == "192.168.1.20"
result.get(NODE_2).getAttributes().get("ansible_user") == "user3"
result.get(NODE_2).getAttributes().get("http_port") == "8080"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[defaults]
inventory=/home/rundeck/ansible-yaml-parsing/inventory_duplicate_key.yaml
interpreter_python=/usr/bin/python3



Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
all:
hosts:
server1:
ansible_host: 192.168.1.10
ansible_user: user1
# Duplicate key!
ansible_user: user2 # This will cause the warning

server2:
ansible_host: 192.168.1.20
ansible_user: user3

vars:
http_port: 80
# Another duplicate key!
http_port: 8080 # This will also cause the warning
3 changes: 2 additions & 1 deletion functional-test/src/test/resources/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ services:
networks:
- rundeck
ports:
- "4440"
- "4440:4440"
volumes:
- ./ansible:/home/rundeck/ansible:rw
- ./ansible-list:/home/rundeck/ansible-list:rw
- ./ansible-yaml-parsing:/home/rundeck/ansible-yaml-parsing:rw

volumes:
rundeck-data:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
by:
urn: project:ansible-yaml-parsing
for:
storage:
- match:
path: 'keys/.*'
allow: [read]
description: Allow access to key storage
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#edit below
project.disable.executions=false
project.disable.schedule=false
project.execution.history.cleanup.batch=500
project.execution.history.cleanup.enabled=false
project.execution.history.cleanup.retention.days=60
project.execution.history.cleanup.retention.minimum=50
project.execution.history.cleanup.schedule=0 0 0 1/1 * ? *
project.jobs.gui.groupExpandLevel=1
project.later.executions.disable.value=0
project.later.executions.disable=false
project.later.executions.enable.value=
project.later.executions.enable=false
project.later.schedule.disable.value=
project.later.schedule.disable=false
project.later.schedule.enable.value=
project.later.schedule.enable=false
project.name=ansible-yaml-parsing
project.nodeCache.enabled=false
project.nodeCache.firstLoadSynch=true
project.output.allowUnsanitized=false
project.retry-counter=3
project.ssh-authentication=privateKey
resources.source.1.type=local
resources.source.2.config.ansible-config-file-path=/home/rundeck/ansible-yaml-parsing/ansible.cfg
resources.source.2.config.ansible-gather-facts=false
resources.source.2.config.ansible-ignore-errors=true
resources.source.2.config.ansible-inventory=/home/rundeck/ansible-yaml-parsing/inventory_duplicate_key.yaml
resources.source.2.type=com.batix.rundeck.plugins.AnsibleResourceModelSourceFactory
service.FileCopier.default.provider=sshj-scp
service.NodeExecutor.default.provider=sshj-ssh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public String getNodeList() throws IOException, AnsibleException {
processAnsibleVault(stdinVariables, procArgs);
processLimit(procArgs);

procArgs.add("2>/dev/null");

String allCmd = String.join(" ", procArgs);

procArgs.clear();
procArgs.add("bash");
procArgs.add("-c");
procArgs.add(allCmd);

if(debug){
System.out.println("getNodeList " + procArgs);
}
Expand Down
Loading